private IQldbDriver GetDriver()
        {
            AmazonQLDBSessionConfig sessionConfig = new AmazonQLDBSessionConfig();

            sessionConfig.RegionEndpoint = RegionEndpoint.USEast1;
            return((IQldbDriver)PooledQldbDriver.Builder().WithAWSCredentials((AWSCredentials)this.awsCredentials).WithQLDBSessionConfig(sessionConfig).WithLedger(Global.LedgerName).Build());
        }
        public void SetupTest()
        {
            mockClient = new Mock <AmazonQLDBSessionClient>();
            var sendCommandResponse = new SendCommandResponse
            {
                StartSession = new StartSessionResult
                {
                    SessionToken = "testToken"
                },
                StartTransaction = new StartTransactionResult
                {
                    TransactionId = "testTransactionIdddddd"
                },
                ExecuteStatement = new ExecuteStatementResult
                {
                    FirstPage = new Page
                    {
                        NextPageToken = null,
                        Values        = new List <ValueHolder>()
                    }
                },
                CommitTransaction = new CommitTransactionResult
                {
                    CommitDigest = new MemoryStream(digest)
                },
                ResponseMetadata = new ResponseMetadata
                {
                    RequestId = "testId"
                }
            };

            mockClient.Setup(x => x.SendCommandAsync(It.IsAny <SendCommandRequest>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(sendCommandResponse));
            builder = PooledQldbDriver.Builder().WithLedger("testLedger");
        }
        public void TestGetSessionFromDriverWithSessionReturnedToPool()
        {
            var sendCommandResponseWithStartSession = new SendCommandResponse
            {
                StartSession = new StartSessionResult
                {
                    SessionToken = "testToken"
                },
                ResponseMetadata = new ResponseMetadata
                {
                    RequestId = "testId"
                }
            };
            var sendCommandResponseEmpty = new SendCommandResponse();

            mockClient.SetupSequence(x => x.SendCommandAsync(It.IsAny <SendCommandRequest>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(sendCommandResponseWithStartSession))
            .Returns(Task.FromResult(sendCommandResponseEmpty));
            builder = PooledQldbDriver.Builder().WithLedger("testLedger");

            var driver  = new PooledQldbDriver("ledgerName", mockClient.Object, 4, 4, 4, NullLogger.Instance);
            var session = driver.GetSession();

            session.Dispose();
            session = driver.GetSession();
            Assert.IsNotNull(session);
            // Once for start session, once for abort. Second will throw exception if start session due to empty response.
            mockClient.Verify(x => x.SendCommandAsync(It.IsAny <SendCommandRequest>(), It.IsAny <CancellationToken>()),
                              Times.Exactly(2));
        }
Example #4
0
        public async Task <string> FunctionHandler(KinesisEvent kinesisEvent)
        {
            foreach (var record in kinesisEvent.Records)
            {
                LambdaLogger.Log(GetRecordContents(record.Kinesis));
            }

            var builder = PooledQldbDriver.Builder();
            var driver  = builder.WithLedger("demo-ledger-1").Build();
            var session = driver.GetSession();

            return(kinesisEvent.ToString());
        }
Example #5
0
        static void Main(string[] args)
        {
            var builder         = PooledQldbDriver.Builder();
            var driver          = builder.WithLedger("demo-ledger-1").Build();
            var session         = driver.GetSession();
            var personForCreate = new Person("akinama", "taro");

            session.Execute($"INSERT INTO Person << {personForCreate.ToJson()} >>;");
            var ion    = session.Execute("SELECT * FROM Person") as BufferedResult;
            var people = new List <Person>();

            foreach (var ionValue in ion)
            {
                var person = new Person(ionValue);
                people.Add(person);
                Console.WriteLine($"FirstName: {person.FirstName}, LastName: {person.LastName}, CreatedAt: {person.CreatedAt}");
            }
        }