Exemplo n.º 1
0
        public async Task Can_recover_from_shutdown_with_twoway_replication()
        {
            var           dataDirectory = "Data" + Guid.NewGuid();
            ICounterStore storeA        = null;
            RavenDbServer server        = null;

            try
            {
                server = GetNewServer(port: 8091, runInMemory: false, dataDirectory: dataDirectory);
                storeA = NewRemoteCountersStore(DefaultCounterStorageName + "A", ravenServer: server);

                using (var storeB = NewRemoteCountersStore(DefaultCounterStorageName + "B"))
                {
                    await SetupReplicationAsync(storeA, storeB);
                    await SetupReplicationAsync(storeB, storeA);

                    storeA.Dispose();
                    server.Dispose();
                    server = GetNewServer(port: 8091, runInMemory: false, dataDirectory: dataDirectory);
                    storeA = NewRemoteCountersStore(DefaultCounterStorageName + "A", ravenServer: server);

                    await storeA.ChangeAsync("group", "counter", 2);

                    await storeB.ChangeAsync("group", "counter", 3);

                    Assert.True(await WaitForReplicationBetween(storeA, storeB, "group", "counter"));
                }
            }
            finally
            {
                storeA?.Dispose();
                server?.Dispose();
                IOExtensions.DeleteDirectory(dataDirectory);
            }
        }
        private static async Task SetupCounters(ICounterStore store, int groupCount, int countersInEachGroupCount)
        {
            const char initialSuffix = 'a';

            for (int group = 0; group < groupCount; group++)
            {
                for (int counter = 0; counter < countersInEachGroupCount; counter++)
                {
                    var groupName   = "g" + (char)(initialSuffix + group);
                    var counterName = "c" + (char)(initialSuffix + counter);
                    await store.ChangeAsync(groupName, counterName, counter + 1);
                }
            }
        }