Ejemplo n.º 1
0
        public async Task TestAppFlowToStore()
        {
            int eventCount = 1000;

            var s1 = Log.MethodEntered("InMemoryKeyValueStore");
            {
                IKeyValueStore store   = new InMemoryKeyValueStore();
                AppFlowToStore appFlow = new AppFlowToStore(store.GetTypeAdapter <AppFlowEvent>());
                await TestAppFlowWithStore(eventCount, appFlow); // Run the tests

                Log.MethodDone(s1, maxAllowedTimeInMs: 1000);
            }
            var s2 = Log.MethodEntered("InMemory FileSystem");
            {
                var            dir1    = EnvironmentV2.instance.GetNewInMemorySystem().GetChildDir("TestAppFlowToFiles");
                IKeyValueStore store   = new FileBasedKeyValueStore(dir1.CreateV2());
                AppFlowToStore appFlow = new AppFlowToStore(store.GetTypeAdapter <AppFlowEvent>());
                await TestAppFlowWithStore(eventCount, appFlow); // Run the tests

                Assert.Equal(eventCount, dir1.GetFiles().Count());
                Log.MethodDone(s2, maxAllowedTimeInMs: 10000);
            }
            var s3 = Log.MethodEntered("Real FileSystem");
            {
                var dir2 = EnvironmentV2.instance.GetRootTempFolder().GetChildDir("TestAppFlowToFiles");
                dir2.DeleteV2(); // Cleanup from last test
                IKeyValueStore store   = new FileBasedKeyValueStore(dir2.CreateV2());
                AppFlowToStore appFlow = new AppFlowToStore(store.GetTypeAdapter <AppFlowEvent>());
                await TestAppFlowWithStore(eventCount, appFlow); // Run the tests

                Assert.Equal(eventCount, dir2.GetFiles().Count());
                Log.MethodDone(s3, maxAllowedTimeInMs: 10000);
            }
            float ratioInMemVsReadFs = s2.ElapsedMilliseconds / (float)s3.ElapsedMilliseconds;

            Assert.True(0.01 < ratioInMemVsReadFs && ratioInMemVsReadFs < 1, $"s2={s2} > s3={s3}, ratioInMemVsReadFs={ratioInMemVsReadFs}");
        }