public void TestReleaseLockExceptionNoSseInfo()
        {
            DeleteStorage();
            // SSE情報なしでストレージに保存
            SaveInstallationToStorage(true, false);

            var res = new Mock <HttpWebResponse>();

            NbSsePushReceiveClient client = new NbSsePushReceiveClient();

            // Main
            Assert.IsFalse(client.AutoRecovery(HttpStatusCode.Unauthorized, res.Object));

            // Check ReleaseLock
            try
            {
                // AcquireLock()でExceptionが起きないことを確認
                NbSsePushReceiveClient.AcquireLock();
            }
            catch (Exception)
            {
                Assert.Fail("Exception");
            }

            NbSsePushReceiveClient.ReleaseLock();
        }
        public void TestAutoRecoveryNormal()
        {
            NbSsePushReceiveClient client = new NbSsePushReceiveClient();

            var res          = new Mock <HttpWebResponse>();
            var responseBody = CreateBody(true, true);
            var response     = new MockRestResponse(HttpStatusCode.OK, responseBody.ToString());

            executor.AddResponse(response);

            // Main
            client.AutoRecovery(HttpStatusCode.Unauthorized, res.Object);

            // Check Request
            CheckRequest();

            // ストレージ内のインスタレーション情報存在チェック
            CheckSaveStorage();

            // Check ReleaseLock
            try
            {
                // AcquireLock()でExceptionが起きないことを確認
                NbSsePushReceiveClient.AcquireLock();
            }
            catch (Exception)
            {
                Assert.Fail("Exception");
            }

            NbSsePushReceiveClient.ReleaseLock();
        }
        public void TestAcquireLockNormalAfterReleaseLockInOtherThread()
        {
            // Main
            try
            {   // ロック1回目
                NbSsePushReceiveClient.AcquireLock();
                // 解除1回
                NbSsePushReceiveClient.ReleaseLock();
            }
            catch (Exception)
            {
                Assert.Fail("Exception");
            }

            try
            {
                Task.Run(() =>
                {
                    NbSsePushReceiveClient.AcquireLock();
                }).Wait();
            }
            catch (AggregateException)
            {
                Assert.Fail("Exception");
            }
            finally
            {
                NbSsePushReceiveClient.ReleaseLock();
            }
        }
Esempio n. 4
0
 public void TearDown()
 {
     if (_client != null)
     {
         NbSsePushReceiveClient.ReleaseLock();
         _client.Disconnect();
         _client._sseClient = null;
         _client            = null;
     }
 }
 public void TestReleaseLockNormalWithoutAcquire()
 {
     try
     {
         // Main
         NbSsePushReceiveClient.ReleaseLock();
     }
     catch (Exception)
     {
         Assert.Fail("Exception");
     }
 }
        public void TestAutoRecoveryExceptionFailLock()
        {
            NbSsePushReceiveClient client = new NbSsePushReceiveClient();

            var res = new Mock <HttpWebResponse>();

            // ロック状態にする
            NbSsePushReceiveClient.AcquireLock();

            // Main
            Assert.IsFalse(client.AutoRecovery(HttpStatusCode.Unauthorized, res.Object));

            NbSsePushReceiveClient.ReleaseLock();
        }
 public void TestAcquireLockNormal()
 {
     // Main
     try
     {
         NbSsePushReceiveClient.AcquireLock();
     }
     catch (Exception)
     {
         Assert.Fail("Exception");
     }
     finally
     {
         // 後始末
         NbSsePushReceiveClient.ReleaseLock();
     }
 }
 public void TestAcquireLockNormalOtherThread()
 {
     try
     {
         Task.Run(() =>
         {
             NbSsePushReceiveClient.AcquireLock();
         }).Wait();
     }
     catch (AggregateException)
     {
         Assert.Fail("Exception");
     }
     finally
     {
         NbSsePushReceiveClient.ReleaseLock();
     }
 }
        public void TestAcquireLockException2TimesFromSubThread()
        {
            try
            {   // ロック1回目
                NbSsePushReceiveClient.AcquireLock();
            }
            catch (Exception)
            {
                Assert.Fail("Exception");
            }

            try
            {
                Task.Run(() =>
                {
                    // ロック2回目(他スレッド)
                    NbSsePushReceiveClient.AcquireLock();
                }).Wait();
                Assert.Fail("No Exception");
            }
            catch (AggregateException ae)
            {
                ae.Handle((x) =>
                {
                    if (x is InvalidOperationException)
                    {
                        // OK
                        return(true);
                    }
                    else
                    {
                        Assert.Fail("Invalid Exception");
                        return(false);
                    }
                });
            }
            finally
            {
                NbSsePushReceiveClient.ReleaseLock();
            }
        }
        public void TestReleaseLockNormal()
        {
            NbSsePushReceiveClient.AcquireLock();

            // Main
            NbSsePushReceiveClient.ReleaseLock();

            try
            {
                // AcquireLock()でExceptionが起きないことを確認
                Task.Run(() =>
                {
                    NbSsePushReceiveClient.AcquireLock();
                    NbSsePushReceiveClient.ReleaseLock();
                }).Wait();
            }
            catch (AggregateException)
            {
                Assert.Fail("Exception");
            }
        }
        public void TestAcquireLockException2Times()
        {
            // Main
            try
            {   // 1回目
                NbSsePushReceiveClient.AcquireLock();
                // 2回目
                NbSsePushReceiveClient.AcquireLock();

                Assert.Fail("No Exception");
            }
            catch (InvalidOperationException)
            {
                // OK
            }
            finally
            {
                // 後始末
                NbSsePushReceiveClient.ReleaseLock();
            }
        }
        public void TestReleaseLockNormalOtherThread()
        {
            NbSsePushReceiveClient.AcquireLock();

            // Main
            Task.Run(() =>
            {
                NbSsePushReceiveClient.ReleaseLock();
            }).Wait();

            try
            {
                // ロックできることを確認
                NbSsePushReceiveClient.AcquireLock();
            }
            catch (InvalidOperationException)
            {
                Assert.Fail("Exception");
            }
            finally
            {
                NbSsePushReceiveClient.ReleaseLock();
            }
        }
Esempio n. 13
0
        public async void TestAutoRecoveryCallbackSaveInstallationFail()
        {
            // For Callback Wait Class
            ManualResetEvent manualEvent = new ManualResetEvent(false);

            // Save Installation
            var installation = await ITUtil.UpsertInstallation();

            // Set Invalid Password
            installation.Password = "******";

            _client = new NbSsePushReceiveClient();

            // Register Error Callback
            _client.RegisterOnError((statusCode, errorInfo) =>
            {
                _errorCalledCount++;

                if (statusCode != HttpStatusCode.Unauthorized)
                {
                    SetAssert("Not Unauthorized Error: " + statusCode.ToString());
                }
                manualEvent.Set();
            });

            // Register Close Callback
            _client.RegisterOnClose(() =>
            {
                // Set Channels Null Before AutoRecovery
                installation.Channels = null;
                _closeCalledCount++;
            });

            // Main
            _client.Connect();

            // Wait for OnError Callback with Timeout
            manualEvent.WaitOne(10000);

            // Test中にAssert.Fail()するとmanualEvent.Setが呼ばれずハングするので、最後にAssertionをthrowする
            if (_isAssertionExists)
            {
                ThrowAssert();
            }

            // Check Release Locked
            try
            {
                NbSsePushReceiveClient.AcquireLock();
            }
            catch (Exception)
            {
                Assert.Fail("Exception");
            }

            NbSsePushReceiveClient.ReleaseLock();

            // Error Callback: Once
            Assert.AreEqual(1, _errorCalledCount);

            // Close Callback: Once
            Assert.AreEqual(1, _closeCalledCount);
        }