public async void ShouldDisposeConnectionOnNewBeginTxIfBeginTxFailed() { // Given var mockConn = new Mock <IConnection>(); mockConn.Setup(x => x.IsOpen).Returns(true); var calls = 0; mockConn.Setup(x => x.Run("BEGIN", null, null, true)) .Callback(() => { // only throw exception on the first beginTx call calls++; if (calls == 1) { throw new IOException("Triggered an error when beginTx"); } }); var session = NewSession(mockConn.Object); var exc = await Record.ExceptionAsync(() => session.BeginTransactionAsync()); exc.Should().BeOfType <IOException>(); // When await session.BeginTransactionAsync(); // Then mockConn.Verify(x => x.CloseAsync(), Times.Once); }
public async void ShouldDisposeConnectionOnNewBeginTxIfBeginTxFailed() { // Given var mockProtocol = new Mock <IBoltProtocol>(); var mockConn = NewMockedConnection(mockProtocol.Object); var calls = 0; mockProtocol.Setup(x => x.BeginTransactionAsync(It.IsAny <IConnection>(), It.IsAny <string>(), It.IsAny <Bookmark>(), It.IsAny <TransactionConfig>())) .Returns(Task.CompletedTask).Callback(() => { // only throw exception on the first beginTx call calls++; if (calls == 1) { throw new IOException("Triggered an error when beginTx"); } }); var session = NewSession(mockConn.Object); var exc = await Record.ExceptionAsync(() => session.BeginTransactionAsync()); exc.Should().BeOfType <IOException>(); // When await session.BeginTransactionAsync(); // Then mockConn.Verify(x => x.CloseAsync(), Times.Once); }
public async Task SingleInvalidRequestAsync() { AmazonDynamoDBConfig config = new AmazonDynamoDBConfig { RegionEndpoint = Amazon.RegionEndpoint.USEast1 }; CSMTestUtilities testUtils = new CSMTestUtilities { Service = "DynamoDB", ApiCall = "DeleteTable", AttemptCount = 1, Domain = "dynamodb.us-east-1.amazonaws.com", Region = "us-east-1", AWSException = "ResourceNotFoundException", AWSExceptionMessage = "Requested resource not found", HttpStatusCode = 400, MaxRetriesExceeded = 0, StashCount = 3 }; var task = Task.Run(() => testUtils.UDPListener()); AmazonDynamoDBClient client = new AmazonDynamoDBClient(config); var exception = await Record.ExceptionAsync(async() => await client.DeleteTableAsync(new DeleteTableRequest { TableName = "foobar" })); Assert.NotNull(exception); Assert.IsType <ResourceNotFoundException>(exception); Thread.Sleep(10); testUtils.EndTest(); task.Wait(); testUtils.Validate(task.Result); }
public async void ShouldDisposeConnectionOnRunIfBeginTxFailed() { // Given var mockConn = new Mock <IConnection>(); mockConn.Setup(x => x.IsOpen).Returns(true); mockConn.Setup(x => x.Run(It.IsAny <string>(), It.IsAny <IDictionary <string, object> >(), It.IsAny <IMessageResponseCollector>(), It.IsAny <bool>())).Callback <string, IDictionary <string, object>, IMessageResponseCollector, bool>( (s, d, c, b) => { c?.DoneSuccess(); }); mockConn.Setup(x => x.Run("BEGIN", null, null, true)) .Throws(new IOException("Triggered an error when beginTx")); var session = NewSession(mockConn.Object); var exc = await Record.ExceptionAsync(() => session.BeginTransactionAsync()); exc.Should().BeOfType <IOException>(); // When await session.RunAsync("lala"); // Then mockConn.Verify(x => x.CloseAsync(), Times.Once); }
public async void ShouldNotAllowNewTxWhileOneIsRunning() { var mockConn = NewMockedConnection(); var session = NewSession(mockConn.Object); await session.BeginTransactionAsync(); var error = await Record.ExceptionAsync(() => session.BeginTransactionAsync()); error.Should().BeOfType<ClientException>(); }
public async void ShouldNotBeAbleToUseSessionWhileOngoingTransaction() { var mockConn = NewMockedConnection(); var session = NewSession(mockConn.Object); var tx = await session.BeginTransactionAsync(); var error = await Record.ExceptionAsync(() => session.RunAsync("lalal")); error.Should().BeOfType<ClientException>(); }
public async void ShouldNotAllowNewTxWhileOneIsRunning() { var mockConn = new Mock <IConnection>(); mockConn.Setup(x => x.IsOpen).Returns(true); var session = NewSession(mockConn.Object); await session.BeginTransactionAsync(); var error = await Record.ExceptionAsync(() => session.BeginTransactionAsync()); error.Should().BeOfType <ClientException>(); }
public async Task ShouldThrowWhenNoRecord() { // Given var connMock = SetupSocketConnection(new List <object[]>()); var manager = new ClusterDiscovery(null, null); // When var exception = await Record.ExceptionAsync(() => manager.DiscoverAsync(connMock.Object)); // Then exception.Should().BeOfType <InvalidOperationException>().Which.Message.Should() .Be("The result is empty."); connMock.Verify(x => x.CloseAsync(), Times.Once); }
public async Task ShouldThrowWhenRecordUnparsable() { // Given var connMock = SetupSocketConnection(new object[] { 1 }); var manager = new ClusterDiscovery(null, null); // When var exception = await Record.ExceptionAsync(() => manager.DiscoverAsync(connMock.Object)); // Then exception.Should().BeOfType <ProtocolException>().Which.Message.Should() .Be("keys (2) does not equal to values (1)"); connMock.Verify(x => x.CloseAsync(), Times.Once); }
public async void ShouldDisposeConnectionIfBeginTxFailed() { var mockConn = new Mock <IConnection>(); mockConn.Setup(x => x.IsOpen).Returns(true); mockConn.Setup(x => x.Run("BEGIN", null, null, true)) .Throws(new IOException("Triggered an error when beginTx")); var session = NewSession(mockConn.Object); var error = await Record.ExceptionAsync(() => session.BeginTransactionAsync()); error.Should().BeOfType <IOException>(); await session.CloseAsync(); mockConn.Verify(x => x.CloseAsync(), Times.Once); }
public async void ShouldThrowIOExceptionIfFailedToReadOnHandshakeAsync() { var bufferSettings = new BufferSettings(Config.Default); var connMock = new Mock <ITcpSocketClient>(); TcpSocketClientTestSetup.CreateReadStreamMock(connMock); TcpSocketClientTestSetup.CreateWriteStreamMock(connMock); var client = new SocketClient(FakeUri, null, bufferSettings, socketClient: connMock.Object); var ex = await Record.ExceptionAsync(() => client.ConnectAsync(new Dictionary <string, string>())); ex.Should().NotBeNull().And.BeOfType <IOException>(); }
public async Task ShouldThrowExceptionIfReaderIsEmpty() { // Given var procedureReplyRecordFields = CreateGetServersResponseRecordFields(3, 1, 0); var connMock = SetupSocketConnection(procedureReplyRecordFields); var manager = new ClusterDiscovery(null, null); // When var exception = await Record.ExceptionAsync(() => manager.DiscoverAsync(connMock.Object)); // Then exception.Should().BeOfType <ProtocolException>().Which.Message.Should() .Contain("3 routers, 1 writers and 0 readers."); connMock.Verify(x => x.CloseAsync(), Times.Once); }
public async Task ShouldThrowClientErrorIfFailedToConnectToServerWithinTimeout() { // Given var mockClient = new Mock <ISocketClient>(); mockClient.Setup(x => x.ConnectAsync()) .Throws(new IOException("I will stop socket conn from initialization")); // ReSharper disable once ObjectCreationAsStatement var conn = new SocketConnection(mockClient.Object, AuthToken, UserAgent, Logger, Server); // When var error = await Record.ExceptionAsync(() => conn.InitAsync()); // Then error.Should().BeOfType <IOException>(); error.Message.Should().Be("I will stop socket conn from initialization"); }
public async void ShouldDisposeConnectionIfBeginTxFailed() { var mockProtocol = new Mock <IBoltProtocol>(); var mockConn = NewMockedConnection(mockProtocol.Object); mockProtocol.Setup(x => x.BeginTransactionAsync(It.IsAny <IConnection>(), It.IsAny <Bookmark>())) .Throws(new IOException("Triggered an error when beginTx")); var session = NewSession(mockConn.Object); var error = await Record.ExceptionAsync(() => session.BeginTransactionAsync()); error.Should().BeOfType <IOException>(); await session.CloseAsync(); mockConn.Verify(x => x.SyncAsync(), Times.Once); mockConn.Verify(x => x.CloseAsync(), Times.Once); }
public async Task WebExceptionRetryableRequestsWithHttpStatusCodeTestAsync() { AmazonDynamoDBConfig config = new AmazonDynamoDBConfig { RegionEndpoint = Amazon.RegionEndpoint.USEast1, MaxErrorRetry = 2 }; CSMTestUtilities testUtils = new CSMTestUtilities { Service = "DynamoDB", ApiCall = "PutItem", Domain = "dynamodb.us-east-1.amazonaws.com", Region = "us-east-1", AttemptCount = config.MaxErrorRetry + 1, SdkException = "AmazonServiceException", SdkExceptionMessage = "WebException", HttpStatusCode = 400, MaxRetriesExceeded = 1, StashCount = config.MaxErrorRetry + 3 }; var task = Task.Run(() => testUtils.UDPListener()); var errorResponse = new Mock <HttpWebResponse>(); exceptionType = new WebException("Test exception", null, WebExceptionStatus.ConnectFailure, errorResponse.Object); errorResponse.SetupGet(foo => foo.StatusCode).Returns(HttpStatusCode.BadRequest); AmazonDynamoDBClient client = new MockDDBClient(config, exceptionType); Random generator = new Random(); Dictionary <string, AttributeValue> attributes = new Dictionary <string, AttributeValue>(); attributes["TestAttribute"] = new AttributeValue { S = generator.Next(0, 999999).ToString("D6") }; PutItemRequest request = new PutItemRequest { TableName = "TestTable", Item = attributes }; var exception = await Record.ExceptionAsync(async() => await client.PutItemAsync(request)); Assert.NotNull(exception); Assert.IsType <AmazonServiceException>(exception); Assert.IsType <WebException>(exception.InnerException); Thread.Sleep(10); testUtils.EndTest(); task.Wait(); testUtils.Validate(task.Result); }
public async Task ShouldProtocolErrorWhenMultipleRecord() { // Given var connMock = SetupSocketConnection(new List <object[]> { CreateGetServersResponseRecordFields(3, 2, 1), CreateGetServersResponseRecordFields(3, 2, 1) }); var manager = new ClusterDiscovery(null, null); // When var exception = await Record.ExceptionAsync(() => manager.DiscoverAsync(connMock.Object)); // Then exception.Should().BeOfType <InvalidOperationException>().Which.Message.Should() .Be("The result contains more than one element."); connMock.Verify(x => x.CloseAsync(), Times.Once); }
public async Task IoExceptionRetryableRequestsTestAsync() { AmazonDynamoDBConfig config = new AmazonDynamoDBConfig { RegionEndpoint = Amazon.RegionEndpoint.USEast1, MaxErrorRetry = 0 }; CSMTestUtilities testUtils = new CSMTestUtilities { Service = "DynamoDB", ApiCall = "PutItem", Domain = "dynamodb.us-east-1.amazonaws.com", Region = "us-east-1", AttemptCount = config.MaxErrorRetry + 1, SdkException = "IOException", SdkExceptionMessage = "I/O", MaxRetriesExceeded = 1, StashCount = config.MaxErrorRetry + 3 }; var task = Task.Run(() => testUtils.UDPListener()); exceptionType = new IOException(); AmazonDynamoDBClient client = new MockDDBClient(config, exceptionType); Random generator = new Random(); Dictionary <string, AttributeValue> attributes = new Dictionary <string, AttributeValue>(); attributes["TestAttribute"] = new AttributeValue { S = generator.Next(0, 999999).ToString("D6") }; PutItemRequest request = new PutItemRequest { TableName = "TestTable", Item = attributes }; var exception = await Record.ExceptionAsync(async() => await client.PutItemAsync(request)); Assert.NotNull(exception); Assert.IsType <IOException>(exception); Thread.Sleep(10); testUtils.EndTest(); task.Wait(); testUtils.Validate(task.Result); }
public async void ShouldDisposeConnectionOnRunIfBeginTxFailed() { // Given var mockProtocol = new Mock <IBoltProtocol>(); var mockConn = MockedConnectionWithSuccessResponse(mockProtocol.Object); mockProtocol.Setup(x => x.BeginTransactionAsync(It.IsAny <IConnection>(), It.IsAny <Bookmark>())) .Throws(new IOException("Triggered an error when beginTx")); var session = NewSession(mockConn.Object); var exc = await Record.ExceptionAsync(() => session.BeginTransactionAsync()); exc.Should().BeOfType <IOException>(); // When await session.RunAsync("lala"); // Then mockConn.Verify(x => x.CloseAsync(), Times.Once); }
public async Task ShouldThrowWhenProcedureNotFound() { // Given var pairs = new List <Tuple <IRequestMessage, IResponseMessage> > { MessagePair( new RunMessage("CALL dbms.cluster.routing.getServers", new Dictionary <string, object>()), new FailureMessage("Neo.ClientError.Procedure.ProcedureNotFound", "not found")), MessagePair(PullAll, Ignored) }; var connMock = new MockedConnection(pairs).MockConn; var manager = new ClusterDiscovery(null, null); // When var exception = await Record.ExceptionAsync(() => manager.DiscoverAsync(connMock.Object)); // Then exception.Should().BeOfType <ClientException>().Which.Message.Should() .Contain("not found"); connMock.Verify(x => x.CloseAsync(), Times.Once); }