Esempio n. 1
0
        public async Task TestProjectSynchronization()
        {
            var code = @"class Test { void Method() { } }";

            using (var workspace = TestWorkspace.CreateCSharp(code))
            {
                var project = workspace.CurrentSolution.Projects.First();

                // build checksum
                await project.State.GetChecksumAsync(CancellationToken.None);

                var map = project.GetAssetMap();

                var sessionId = 0;
                var storage   = new AssetStorage();
                var source    = new TestAssetSource(storage, map);

                var service = new AssetService(sessionId, storage);
                await service.SynchronizeProjectAssetsAsync(SpecializedCollections.SingletonEnumerable(await project.State.GetChecksumAsync(CancellationToken.None)), CancellationToken.None);

                foreach (var kv in map)
                {
                    Assert.True(storage.TryGetAsset(kv.Key, out object data));
                }
            }
        }
Esempio n. 2
0
        public async Task TestSolutionSynchronization()
        {
            var code = @"class Test { void Method() { } }";

            using (var workspace = TestWorkspace.CreateCSharp(code))
            {
                var solution = workspace.CurrentSolution;

                // build checksum
                await solution.State.GetChecksumAsync(CancellationToken.None);

                var map = solution.GetAssetMap();

                var sessionId = 0;
                var storage   = new AssetStorage();
                var source    = new TestAssetSource(storage, map);

                var service = new AssetService(sessionId, storage);
                await service.SynchronizeSolutionAssetsAsync(await solution.State.GetChecksumAsync(CancellationToken.None), CancellationToken.None);

                foreach (var kv in map)
                {
                    Assert.True(storage.TryGetAsset(kv.Key, out object data));
                }
            }
        }
Esempio n. 3
0
        public async Task TestAssetSynchronization()
        {
            var code = @"class Test { void Method() { } }";

            using var workspace = TestWorkspace.CreateCSharp(code);
            var solution = workspace.CurrentSolution;

            // build checksum
            await solution.State.GetChecksumAsync(CancellationToken.None);

            var map = await solution.GetAssetMapAsync(CancellationToken.None);

            var sessionId = 0;
            var storage   = new AssetStorage();

            storage.Initialize(new SimpleAssetSource(map));

            var service = new AssetProvider(sessionId, storage, new RemoteWorkspace().Services.GetService <ISerializerService>());
            await service.SynchronizeAssetsAsync(new HashSet <Checksum>(map.Keys), CancellationToken.None);

            foreach (var kv in map)
            {
                Assert.True(storage.TryGetAsset <object>(kv.Key, out _));
            }
        }
Esempio n. 4
0
        public async Task TestAssetSynchronization()
        {
            var code = @"class Test { void Method() { } }";

            using (var workspace = await TestWorkspace.CreateCSharpAsync(code))
            {
                var solution = workspace.CurrentSolution;

                // build checksum
                await solution.State.GetChecksumAsync(CancellationToken.None);

                var map = solution.GetAssetMap();

                var sessionId = 0;
                var storage = new AssetStorage();
                var source = new TestAssetSource(storage, sessionId, map);

                var service = new AssetService(sessionId, storage);
                await service.SynchronizeAssetsAsync(new HashSet<Checksum>(map.Keys), CancellationToken.None);

                object data;
                foreach (var kv in map)
                {
                    Assert.True(storage.TryGetAsset(kv.Key, out data));
                }
            }
        }
Esempio n. 5
0
        public void TestGetAssets()
        {
            var storage = new AssetStorage();

            var checksum = Checksum.Create(WellKnownSynchronizationKind.Null, ImmutableArray.CreateRange(Guid.NewGuid().ToByteArray()));
            var data     = new object();

            Assert.True(storage.TryAddAsset(checksum, data));

            Assert.True(storage.TryGetAsset(checksum, out object stored));
        }
Esempio n. 6
0
        public void TestGetAssets()
        {
            var storage = new AssetStorage();

            var checksum = new Checksum(Guid.NewGuid().ToByteArray());
            var data = new object();

            Assert.True(storage.TryAddAsset(checksum, data));

            object stored;
            Assert.True(storage.TryGetAsset(checksum, out stored));
        }
Esempio n. 7
0
        public void TestGetAssets()
        {
            var storage = new AssetStorage();

            var checksum = new Checksum(Guid.NewGuid().ToByteArray());
            var data     = new object();

            Assert.True(storage.TryAddAsset(checksum, data));

            object stored;

            Assert.True(storage.TryGetAsset(checksum, out stored));
        }
Esempio n. 8
0
        public void TestGetAssets()
        {
            var sessionId = 0;

            var storage = new AssetStorage(enableCleanup: false);
            var source = new MyAssetSource(storage, sessionId);

            var checksum = new Checksum(Guid.NewGuid().ToByteArray());
            var data = new object();

            Assert.True(storage.TryAddAsset(checksum, data));

            object stored;
            Assert.True(storage.TryGetAsset(checksum, out stored));
        }
        public void TestGetAssets()
        {
            var sessionId = 0;

            var storage = new AssetStorage(enableCleanup: false);
            var source  = new MyAssetSource(storage, sessionId);

            var checksum = new Checksum(Guid.NewGuid().ToByteArray());
            var data     = new object();

            Assert.True(storage.TryAddAsset(checksum, data));

            object stored;

            Assert.True(storage.TryGetAsset(checksum, out stored));
        }
Esempio n. 10
0
        public static void VerifyAssetStorage <T>(IEnumerable <KeyValuePair <Checksum, T> > items, AssetStorage storage)
        {
            foreach (var kv in items)
            {
                if (kv.Value is ChecksumCollection)
                {
                    // ChecksumCollection itself won't be in asset storage. since
                    // it will be never asked from OOP side to host to sync.
                    // the collection is already part of
                    // Solution/Project/DocumentStateCheckum so syncing
                    // state checksum automatically bring in the collection.
                    // it only exist to calculate hierarchical checksum
                    continue;
                }

                Assert.True(storage.TryGetAsset(kv.Key, out object data));
            }
        }
Esempio n. 11
0
        public async Task TestCleanup()
        {
            var storage = new AssetStorage(cleanupInterval: TimeSpan.FromMilliseconds(1), purgeAfter: TimeSpan.FromMilliseconds(2), gcAfter: TimeSpan.FromMilliseconds(5));

            var checksum = Checksum.Create(WellKnownSynchronizationKind.Null, ImmutableArray.CreateRange(Guid.NewGuid().ToByteArray()));
            var data     = new object();

            Assert.True(storage.TryAddAsset(checksum, data));

            for (var i = 0; i < 10; i++)
            {
                await Task.Delay(10);

                if (!storage.TryGetAsset(checksum, out object stored))
                {
                    // asset is deleted
                    return;
                }
            }

            // it should not reach here
            Assert.True(false, "asset not cleaned up");
        }
Esempio n. 12
0
        public async Task TestCleanup()
        {
            var storage = new AssetStorage(cleanupInterval: TimeSpan.FromMilliseconds(1), purgeAfter: TimeSpan.FromMilliseconds(2));

            var checksum = new Checksum(Guid.NewGuid().ToByteArray());
            var data = new object();

            Assert.True(storage.TryAddAsset(checksum, data));

            for (var i = 0; i < 10; i++)
            {
                await Task.Delay(10);

                object stored;
                if (!storage.TryGetAsset(checksum, out stored))
                {
                    // asset is deleted
                    return;
                }
            }

            // it should not reach here
            Assert.True(false, "asset not cleaned up");
        }
Esempio n. 13
0
        public async Task TestCleanup()
        {
            var storage = new AssetStorage(cleanupInterval: TimeSpan.FromMilliseconds(1), purgeAfter: TimeSpan.FromMilliseconds(2));

            var checksum = new Checksum(Guid.NewGuid().ToByteArray());
            var data     = new object();

            Assert.True(storage.TryAddAsset(checksum, data));

            for (var i = 0; i < 10; i++)
            {
                await Task.Delay(10);

                object stored;
                if (!storage.TryGetAsset(checksum, out stored))
                {
                    // asset is deleted
                    return;
                }
            }

            // it should not reach here
            Assert.True(false, "asset not cleaned up");
        }