public async Task InsertEntity()
        {
            var tarantoolClient       = TarantoolClient.Create("mytestuser:mytestpass@tarantool-host:3301");
            var testSpace             = tarantoolClient.GetSpace <MyTestEntity>("test");
            var testSpacePrimaryIndex = testSpace.GetIndex <IndexKey <uint> >(0);
            await testSpacePrimaryIndex.DeleteAsync(new IndexKey <uint>(598));

            var now = DateTime.UtcNow;

            try
            {
                var result = await testSpace.InsertAsync(new MyTestEntity
                {
                    MyTestEntityId     = 598,
                    SomeStringField    = "Some name",
                    SomeIntField       = 1900,
                    SomeDateTimeField  = now,
                    SomeDateTimeFieldN = now,
                    SomeDateTimeFieldU = now
                });

                Assert.Equal(1, result.Count);
                Assert.Equal(598u, result[0].MyTestEntityId);
                Assert.Equal("Some name", result[0].SomeStringField);
                Assert.Equal(1900, result[0].SomeIntField);
                Assert.Equal(now, result[0].SomeDateTimeField);
                Assert.Equal(now, result[0].SomeDateTimeFieldN);
                Assert.Equal((now - result[0].SomeDateTimeFieldU).TotalSeconds, 0, 2);
            }
            finally
            {
                await testSpacePrimaryIndex.DeleteAsync(new IndexKey <uint>(598));
            }
        }
Exemplo n.º 2
0
        public async Task ReplaceEntity()
        {
            var tarantoolClient       = TarantoolClient.Create("mytestuser:mytestpass@tarantool-host:3301");
            var testSpace             = tarantoolClient.GetSpace <MyTestEntity>("test");
            var testSpacePrimaryIndex = testSpace.GetIndex <IndexKey <uint> >(0);

            try
            {
                await testSpace.InsertAsync(new MyTestEntity
                {
                    MyTestEntityId  = 576,
                    SomeStringField = "Some name",
                    SomeIntField    = 1700
                });

                var result = await testSpace.ReplaceAsync(new MyTestEntity
                {
                    MyTestEntityId  = 576,
                    SomeStringField = "Some new name",
                    SomeIntField    = 1776
                });

                Assert.Equal(1, result.Count);
                Assert.Equal(576u, result[0].MyTestEntityId);
                Assert.Equal("Some new name", result[0].SomeStringField);
                Assert.Equal(1776, result[0].SomeIntField);
            }
            finally
            {
                await testSpacePrimaryIndex.DeleteAsync(new IndexKey <uint>(576));
            }
        }
Exemplo n.º 3
0
        public async Task UpdateByEntityField()
        {
            var tarantoolClient       = TarantoolClient.Create("mytestuser:mytestpass@localhost:3301");
            var testSpace             = tarantoolClient.GetSpace <MyTestEntity>("test");
            var testSpacePrimaryIndex = testSpace.GetIndex <IndexKey <uint> >(0);
            var now = DateTime.UtcNow;

            try
            {
                await testSpace.InsertAsync(
                    new MyTestEntity { MyTestEntityId = 566, SomeStringField = "Some name", SomeIntField = 1600 });

                var result = await testSpacePrimaryIndex.UpdateAsync(
                    new IndexKey <uint>(566),
                    new UpdateDefinition <MyTestEntity>()
                    .AddOpertation(x => x.SomeIntField, UpdateOperationCode.Assign, 1666)
                    .AddOpertation(x => x.SomeNullableDateTimeField, UpdateOperationCode.Assign, now));

                Assert.Equal(1, result.Count);
                Assert.Equal(566u, result[0].MyTestEntityId);
                Assert.Equal("Some name", result[0].SomeStringField);
                Assert.Equal(1666, result[0].SomeIntField);
                Assert.Equal((now - result[0].SomeNullableDateTimeField.Value).TotalSeconds, 0, 2);
            }
            finally
            {
                await testSpacePrimaryIndex.DeleteAsync(new IndexKey <uint>(566));
            }
        }
Exemplo n.º 4
0
        public async Task CreateIndex()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@tarantool-host:3301");

            try
            {
                await tarantoolClient.CreateSpaceAsync("testforindex1");

                await tarantoolClient.CreateIndexAsync("testforindex1", "primary", IndexType.Hash,
                                                       new IndexPart(0, IndexedFieldType.Unsigned));

                var spaceId = (await tarantoolClient.FindSpaceByNameAsync("testforindex1")).SpaceId;
                var result  = await tarantoolClient.FindIndexByNameAsync(spaceId, "primary");

                Assert.NotNull(result);
                Assert.NotNull(result);
                Assert.Equal(spaceId, result.SpaceId);
                Assert.Equal("primary", result.Name);
                Assert.Equal(IndexType.Hash, result.IndexType);
            }
            finally
            {
                await tarantoolClient.DropSpaceAsync("testforindex1");
            }
        }
        public async Task UpsertAsUpdate()
        {
            var tarantoolClient       = TarantoolClient.Create("mytestuser:mytestpass@tarantool-host:3301");
            var testSpace             = tarantoolClient.GetSpace <MyTestEntity>("test");
            var testSpacePrimaryIndex = testSpace.GetIndex <IndexKey <uint> >(0);

            try
            {
                await testSpace.InsertAsync(new MyTestEntity
                {
                    MyTestEntityId  = 544,
                    SomeStringField = "Some name",
                    SomeIntField    = 1400
                });

                await testSpace.UpsertAsync(
                    new MyTestEntity { MyTestEntityId = 544, SomeStringField = "Some name", SomeIntField = 1440 },
                    new UpdateDefinition <MyTestEntity>().AddOpertation(
                        x => x.SomeIntField,
                        UpdateOperationCode.Assign,
                        1444));

                var result = await testSpacePrimaryIndex.SelectAsync(new IndexKey <uint>(544));

                Assert.Equal(1, result.Count);
                Assert.Equal(544u, result[0].MyTestEntityId);
                Assert.Equal("Some name", result[0].SomeStringField);
                Assert.Equal(1444, result[0].SomeIntField);
            }
            finally
            {
                await testSpacePrimaryIndex.DeleteAsync(new IndexKey <uint>(544));
            }
        }
Exemplo n.º 6
0
        public async Task NotConnectAsInvalidUser()
        {
            var tarantoolClient = TarantoolClient.Create(
                "invaliduser:invalidpass@tarantool-host:3301,tarantool-host:3302,tarantool-host:3303");

            var ex = await Assert.ThrowsAsync <TarantoolException>(() => tarantoolClient.ConnectAsync());

            Assert.Equal("User 'invaliduser' is not found", ex.Message);
        }
Exemplo n.º 7
0
        public async Task SelectSpaceId()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@localhost:3301");

            var result = await tarantoolClient.FindSpaceByNameAsync("_vspace");

            Assert.NotNull(result);
            Assert.Equal(281u, result.SpaceId);
            Assert.Equal("_vspace", result.Name);
        }
Exemplo n.º 8
0
        public async Task UpsertAsUpdate()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@localhost:3301");
            var testSpaceId     = (await tarantoolClient.FindSpaceByNameAsync("test")).SpaceId;

            try
            {
                await tarantoolClient.RequestAsync(new InsertRequest
                {
                    SpaceId = testSpaceId,
                    Tuple   = new List <object> {
                        44, "Some name", 1400
                    }
                });

                await tarantoolClient.UpsertAsync(new UpsertRequest
                {
                    SpaceId = testSpaceId,
                    Tuple   = new List <object> {
                        44, "Some name", 1440
                    },
                    UpdateOperations = new[]
                    {
                        new UpdateOperation <int>
                        {
                            Operation = UpdateOperationCode.Assign,
                            FieldNo   = 2,
                            Argument  = 1444
                        }
                    }
                });

                var result = await tarantoolClient.SelectAsync(new SelectRequest
                {
                    SpaceId = testSpaceId,
                    Key     = new List <object> {
                        44
                    }
                });

                Assert.Equal(1, result.Count);
                Assert.Equal(new[] { "44", "Some name", "1444" },
                             result[0].AsList().Select(x => x.ToObject().ToString()).ToArray());
            }
            finally
            {
                await tarantoolClient.RequestAsync(new DeleteRequest
                {
                    SpaceId = testSpaceId,
                    Key     = new List <object> {
                        44
                    }
                });
            }
        }
        public async Task EvaluateScalars()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@tarantool-host:3301");

            var result = (await tarantoolClient.EvalAsync(new EvalRequest
            {
                Expression = "return 12345, 23456, 34567"
            })).AsList();

            Assert.Equal(new[] { 12345, 23456, 34567 }, result.Select(x => x.AsInt32()));
        }
        public async Task SelectIndexId()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@tarantool-host:3301");

            var result = await tarantoolClient.FindIndexByNameAsync(281, "owner");

            Assert.NotNull(result);
            Assert.Equal(281u, result.SpaceId);
            Assert.Equal(1u, result.IndexId);
            Assert.Equal("owner", result.Name);
        }
Exemplo n.º 11
0
        public async Task SelectBy1()
        {
            var tarantoolClient       = TarantoolClient.Create("mytestuser:mytestpass@localhost:3301");
            var testSpace             = tarantoolClient.GetSpace <MessagePackObject>("test");
            var testSpacePrimaryIndex = testSpace.GetIndex <IndexKey <uint> >(0);

            var result = await testSpacePrimaryIndex.SelectAsync(new IndexKey <uint>(1));

            Assert.Equal(1, result.Count);
            Assert.Equal(new[] { "1", "Roxette" }, result[0].AsList().Select(x => x.ToObject().ToString()).ToArray());
        }
Exemplo n.º 12
0
        public async Task CallSomeFunction()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@localhost:3301");

            var result = (await tarantoolClient.CallAsync(new CallRequest
            {
                FunctionName = "some_function"
            })).AsList();

            Assert.True(result.Count == 1);
            Assert.Equal("ok", result[0].AsString());
        }
Exemplo n.º 13
0
        public async Task SelectEntityBy1()
        {
            var tarantoolClient       = TarantoolClient.Create("mytestuser:mytestpass@localhost:3301");
            var testSpace             = tarantoolClient.GetSpace <MyTestEntity>("test");
            var testSpacePrimaryIndex = testSpace.GetIndex <IndexKey <uint> >(0);

            var result = await testSpacePrimaryIndex.SelectAsync(new IndexKey <uint>(1));

            Assert.Equal(1, result.Count);
            Assert.Equal(1u, result[0].MyTestEntityId);
            Assert.Equal("Roxette", result[0].SomeStringField);
        }
        public async Task EvaluateScalarsFromArguments()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@tarantool-host:3301");

            var result = (await tarantoolClient.EvalAsync(new EvalRequest
            {
                Expression = "return ...",
                Args = new List <object> {
                    912345, 923456, 934567
                }
            })).AsList();

            Assert.Equal(new[] { 912345, 923456, 934567 }, result.Select(x => x.AsInt32()));
        }
        public async Task SelectBy3()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@tarantool-host:3301");
            var testSpaceId     = (await tarantoolClient.FindSpaceByNameAsync("test")).SpaceId;

            var result = await tarantoolClient.SelectAsync(new SelectRequest
            {
                SpaceId = testSpaceId,
                Key     = new object[] { 3 }
            });

            Assert.Equal(1, result.Count);
            Assert.Equal(new[] { "3", "Ace of Base", "1993" },
                         result[0].AsList().Select(x => x.ToObject().ToString()).ToArray());
        }
Exemplo n.º 16
0
        public async Task SelectAll()
        {
            var tarantoolClient       = TarantoolClient.Create("mytestuser:mytestpass@localhost:3301");
            var testSpace             = tarantoolClient.GetSpace <MessagePackObject>("test");
            var testSpacePrimaryIndex = testSpace.GetIndex <IndexKey <uint> >(0);

            var result = await testSpacePrimaryIndex.SelectAsync();

            Assert.True(result.Count >= 3);
            Assert.Equal(new[] { "1", "Roxette" }, result[0].AsList().Select(x => x.ToObject().ToString()).ToArray());
            Assert.Equal(new[] { "2", "Scorpions", "2015" },
                         result[1].AsList().Select(x => x.ToObject().ToString()).ToArray());
            Assert.Equal(new[] { "3", "Ace of Base", "1993" },
                         result[2].AsList().Select(x => x.ToObject().ToString()).ToArray());
        }
Exemplo n.º 17
0
        public async Task SelectBy1()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@localhost:3301");
            var testSpaceId     = (await tarantoolClient.FindSpaceByNameAsync("test")).SpaceId;

            var result = await tarantoolClient.SelectAsync(new SelectRequest
            {
                SpaceId = testSpaceId,
                Key     = new List <dynamic> {
                    1
                }
            });

            Assert.Equal(1, result.Count);
            Assert.Equal(new[] { "1", "Roxette" }, result[0].AsList().Select(x => x.ToObject().ToString()).ToArray());
        }
        public async Task SelectAll()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@tarantool-host:3301");
            var testSpaceId     = (await tarantoolClient.FindSpaceByNameAsync("test")).SpaceId;

            var result = await tarantoolClient.SelectAsync(new SelectRequest
            {
                SpaceId  = testSpaceId,
                Iterator = Iterator.All
            });

            Assert.True(result.Count >= 3);
            Assert.Equal(new[] { "1", "Roxette" }, result[0].AsList().Select(x => x.ToObject().ToString()).ToArray());
            Assert.Equal(new[] { "2", "Scorpions", "2015" },
                         result[1].AsList().Select(x => x.ToObject().ToString()).ToArray());
            Assert.Equal(new[] { "3", "Ace of Base", "1993" },
                         result[2].AsList().Select(x => x.ToObject().ToString()).ToArray());
        }
        public async Task CreateSpace()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@tarantool-host:3301");

            try
            {
                await tarantoolClient.CreateSpaceAsync("test2");

                var result = await tarantoolClient.FindSpaceByNameAsync("test2");

                Assert.NotNull(result);
                Assert.Equal("test2", result.Name);
            }
            finally
            {
                await tarantoolClient.DropSpaceAsync("test2");
            }
        }
        public async Task HandleSpaceExists()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@tarantool-host:3301");

            try
            {
                await Assert.ThrowsAsync <SpaceAlreadyExistsException>(async() =>
                {
                    await tarantoolClient.CreateSpaceAsync("test3");

                    await tarantoolClient.CreateSpaceAsync("test3");
                });
            }
            finally
            {
                await tarantoolClient.DropSpaceAsync("test3");
            }
        }
Exemplo n.º 21
0
        public async Task ReplaceEntity()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@localhost:3301");
            var testSpaceId     = (await tarantoolClient.FindSpaceByNameAsync("test")).SpaceId;

            try
            {
                await tarantoolClient.RequestAsync(new InsertRequest
                {
                    SpaceId = testSpaceId,
                    Tuple   = new List <object> {
                        76, "Some name", 1700
                    }
                });

                var result = await tarantoolClient.ReplaceAsync(new ReplaceRequest <MyTestEntity>
                {
                    SpaceId = testSpaceId,
                    Tuple   = new MyTestEntity
                    {
                        MyTestEntityId  = 76,
                        SomeStringField = "Some new name",
                        SomeIntField    = 1776
                    }
                });

                Assert.Equal(1, result.Count);
                Assert.Equal(76u, result[0].MyTestEntityId);
                Assert.Equal("Some new name", result[0].SomeStringField);
                Assert.Equal(1776, result[0].SomeIntField);
            }
            finally
            {
                await tarantoolClient.RequestAsync(new DeleteRequest
                {
                    SpaceId = testSpaceId,
                    Key     = new List <object> {
                        76
                    }
                });
            }
        }
        public async Task InsertEntity()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@tarantool-host:3301");
            var testSpaceId     = (await tarantoolClient.FindSpaceByNameAsync("test")).SpaceId;
            await tarantoolClient.RequestAsync(new DeleteRequest
            {
                SpaceId = testSpaceId,
                Key     = new List <object> {
                    98
                }
            });

            try
            {
                var result = await tarantoolClient.InsertAsync(new InsertRequest <MyTestEntity>
                {
                    SpaceId = testSpaceId,
                    Tuple   = new MyTestEntity
                    {
                        MyTestEntityId  = 98,
                        SomeStringField = "Some name",
                        SomeIntField    = 1900
                    }
                });

                Assert.Equal(1, result.Count);
                Assert.Equal(98u, result[0].MyTestEntityId);
                Assert.Equal("Some name", result[0].SomeStringField);
                Assert.Equal(1900, result[0].SomeIntField);
            }
            finally
            {
                await tarantoolClient.RequestAsync(new DeleteRequest
                {
                    SpaceId = testSpaceId,
                    Key     = new List <object> {
                        98
                    }
                });
            }
        }
Exemplo n.º 23
0
        public async Task HandleIndexExists()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@tarantool-host:3301");

            try
            {
                await Assert.ThrowsAsync <IndexAlreadyExistsException>(async() =>
                {
                    await tarantoolClient.CreateSpaceAsync("testforindex2");
                    await tarantoolClient.CreateIndexAsync("testforindex2", "primary", IndexType.Hash,
                                                           new IndexPart(0, IndexedFieldType.Unsigned));

                    await tarantoolClient.CreateIndexAsync("testforindex2", "primary", IndexType.Hash,
                                                           new IndexPart(0, IndexedFieldType.Unsigned));
                });
            }
            finally
            {
                await tarantoolClient.DropSpaceAsync("testforindex2");
            }
        }
Exemplo n.º 24
0
        public async Task ReplaceRow()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@localhost:3301");
            var testSpaceId     = (await tarantoolClient.FindSpaceByNameAsync("test")).SpaceId;

            try
            {
                await tarantoolClient.RequestAsync(new InsertRequest
                {
                    SpaceId = testSpaceId,
                    Tuple   = new List <object> {
                        77, "Some name", 1700
                    }
                });

                var result = await tarantoolClient.ReplaceAsync(new ReplaceRequest
                {
                    SpaceId = testSpaceId,
                    Tuple   = new List <object> {
                        77, "Some new name", 1777
                    }
                });

                Assert.Equal(1, result.Count);
                Assert.Equal(new[] { "77", "Some new name", "1777" },
                             result[0].AsList().Select(x => x.ToObject().ToString()).ToArray());
            }
            finally
            {
                await tarantoolClient.RequestAsync(new DeleteRequest
                {
                    SpaceId = testSpaceId,
                    Key     = new List <object> {
                        77
                    }
                });
            }
        }
        public async Task InsertRaw()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@tarantool-host:3301");
            var testSpaceId     = (await tarantoolClient.FindSpaceByNameAsync("test")).SpaceId;
            await tarantoolClient.RequestAsync(new DeleteRequest
            {
                SpaceId = testSpaceId,
                Key     = new List <object> {
                    99
                }
            });

            try
            {
                var result = await tarantoolClient.InsertAsync(new InsertRequest
                {
                    SpaceId = testSpaceId,
                    Tuple   = new List <object> {
                        99, "Some name", 1900
                    }
                });

                Assert.Equal(1, result.Count);
                Assert.Equal(new[] { "99", "Some name", "1900" },
                             result[0].AsList().Select(x => x.ToObject().ToString()).ToArray());
            }
            finally
            {
                await tarantoolClient.RequestAsync(new DeleteRequest
                {
                    SpaceId = testSpaceId,
                    Key     = new List <object> {
                        99
                    }
                });
            }
        }
Exemplo n.º 26
0
        public async Task Delete()
        {
            var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@localhost:3301");
            var testSpaceId     = (await tarantoolClient.FindSpaceByNameAsync("test")).SpaceId;
            await tarantoolClient.RequestAsync(new InsertRequest
            {
                SpaceId = testSpaceId,
                Tuple   = new List <object> {
                    88, "Some name", 1800
                }
            });

            var result = await tarantoolClient.DeleteAsync(new DeleteRequest
            {
                SpaceId = testSpaceId,
                Key     = new List <object> {
                    88
                }
            });

            Assert.Equal(1, result.Count);
            Assert.Equal(new[] { "88", "Some name", "1800" },
                         result[0].AsList().Select(x => x.ToObject().ToString()).ToArray());
        }
Exemplo n.º 27
0
 public async Task ConnectAsGuest()
 {
     var tarantoolClient = TarantoolClient.Create("tarantool-host:3301,tarantool-host:3302,tarantool-host:3303");
     await tarantoolClient.ConnectAsync();
 }
Exemplo n.º 28
0
 public async Task ConnectAsUser()
 {
     var tarantoolClient = TarantoolClient.Create("mytestuser:mytestpass@tarantool-host:3301,tarantool-host:3302,tarantool-host:3303");
     await tarantoolClient.ConnectAsync();
 }
Exemplo n.º 29
0
 public async Task ConnectAsGuest()
 {
     var tarantoolClient = TarantoolClient.Create("localhost:3301");
     await tarantoolClient.ConnectAsync();
 }