Esempio n. 1
0
        public async Task PutGetExistOperationUInt64ConcurrentTestAsync(int threadCount)
        {
            byte[] defaultData = new byte[] { 1, 2, 3 };
            var    data        = new ConcurrentDictionary <BobKey, byte[]>();

            data[BobKey.FromUInt64(1)] = defaultData;
            data[BobKey.FromUInt64(ulong.MaxValue)] = defaultData;

            using (var client = new BobNodeClient <ulong>(BobNodeClientMockHelper.CreateMockedClientWithData(data), null, null))
            {
                Barrier bar = new Barrier(threadCount + 1);

                async Task MainAction()
                {
                    bar.SignalAndWait(10000);

                    Assert.Equal(defaultData, await client.GetAsync(1));
                    Assert.Equal(defaultData, await client.GetAsync(ulong.MaxValue));
                    Assert.Throws <BobKeyNotFoundException>(() => client.GetAsync(2).GetAwaiter().GetResult());

                    Assert.Equal(new bool[] { true, false }, await client.ExistsAsync(new ulong[] { 1, 2 }));

                    for (ulong i = 100; i < 10000; i++)
                    {
                        await client.PutAsync(i, defaultData);
                    }
                    for (ulong i = 100; i < 10000; i++)
                    {
                        Assert.Equal(defaultData, await client.GetAsync(i));
                    }
                    Assert.All(await client.ExistsAsync(Enumerable.Range(100, 10000 - 100).Select(o => (ulong)o).ToArray()), res => Assert.True(res));
                    Assert.All(await client.ExistsAsync(Enumerable.Range(20000, 1000).Select(o => (ulong)o).ToArray()), res => Assert.False(res));


                    for (ulong i = uint.MaxValue; i < (ulong)uint.MaxValue + 1000; i++)
                    {
                        await client.PutAsync(i, defaultData);
                    }
                    for (ulong i = uint.MaxValue; i < (ulong)uint.MaxValue + 1000; i++)
                    {
                        Assert.Equal(defaultData, await client.GetAsync(i));
                    }
                }

                Task[] tasks = new Task[threadCount];
                for (int i = 0; i < tasks.Length; i++)
                {
                    tasks[i] = Task.Factory.StartNew(() => MainAction().GetAwaiter().GetResult(), TaskCreationOptions.LongRunning);
                }

                bar.SignalAndWait(10000);

                await Task.WhenAll(tasks);
            }
        }
Esempio n. 2
0
        public async Task PutGetExistOperationInt32TestAsync()
        {
            byte[] defaultData = new byte[] { 1, 2, 3 };
            var    data        = new ConcurrentDictionary <BobKey, byte[]>();

            using (var client = new BobNodeClient <int>(BobNodeClientMockHelper.CreateMockedClientWithData(data), null, null))
            {
                client.Put(1, defaultData);
                client.Put(int.MaxValue, defaultData);

                Assert.Equal(defaultData, await client.GetAsync(1));
                Assert.Equal(defaultData, await client.GetAsync(int.MaxValue));
                Assert.Throws <BobKeyNotFoundException>(() => client.GetAsync(2).GetAwaiter().GetResult());

                Assert.Equal(new bool[] { true, false }, await client.ExistsAsync(new int[] { 1, 2 }));

                for (int i = 100; i < 10000; i++)
                {
                    await client.PutAsync(i, defaultData);
                }
                for (int i = 100; i < 10000; i++)
                {
                    Assert.Equal(defaultData, await client.GetAsync(i));
                }
                Assert.All(await client.ExistsAsync(Enumerable.Range(100, 10000 - 100).Select(o => o).ToArray()), res => Assert.True(res));
                Assert.All(await client.ExistsAsync(Enumerable.Range(20000, 1000).Select(o => o).ToArray()), res => Assert.False(res));


                for (int i = int.MaxValue - 1000; i < int.MaxValue - 1; i++)
                {
                    await client.PutAsync(i, defaultData);
                }
                for (int i = int.MaxValue - 1000; i < int.MaxValue - 1; i++)
                {
                    Assert.Equal(defaultData, await client.GetAsync(i));
                }
            }
        }
Esempio n. 3
0
        public async Task PutGetExistOperationUInt64TestAsync()
        {
            byte[] defaultData = new byte[] { 1, 2, 3 };
            var    data        = new ConcurrentDictionary <BobKey, byte[]>();

            data[BobKey.FromUInt64(1)] = defaultData;
            data[BobKey.FromUInt64(ulong.MaxValue)] = defaultData;

            using (var client = new BobNodeClient <ulong>(BobNodeClientMockHelper.CreateMockedClientWithData(data), null, null))
            {
                Assert.Equal(defaultData, await client.GetAsync(1));
                Assert.Equal(defaultData, await client.GetAsync(ulong.MaxValue));
                Assert.Throws <BobKeyNotFoundException>(() => client.GetAsync(2).GetAwaiter().GetResult());

                Assert.Equal(new bool[] { true, false }, await client.ExistsAsync(new ulong[] { 1, 2 }));

                for (ulong i = 100; i < 10000; i++)
                {
                    await client.PutAsync(i, defaultData);
                }
                for (ulong i = 100; i < 10000; i++)
                {
                    Assert.Equal(defaultData, await client.GetAsync(i));
                }
                Assert.All(await client.ExistsAsync(Enumerable.Range(100, 10000 - 100).Select(o => (ulong)o).ToArray()), res => Assert.True(res));
                Assert.All(await client.ExistsAsync(Enumerable.Range(20000, 1000).Select(o => (ulong)o).ToArray()), res => Assert.False(res));


                for (ulong i = uint.MaxValue; i < (ulong)uint.MaxValue + 1000; i++)
                {
                    await client.PutAsync(i, defaultData);
                }
                for (ulong i = uint.MaxValue; i < (ulong)uint.MaxValue + 1000; i++)
                {
                    Assert.Equal(defaultData, await client.GetAsync(i));
                }
            }
        }