Exemplo n.º 1
0
        public void Test_TAGFileBufferQueue_Creation()
        {
            EnsureServer();

            var queue = new TAGFileBufferQueue();

            Assert.NotNull(queue);
        }
Exemplo n.º 2
0
        public void AddProxyCacheFactoriesToDI()
        {
            _tagFileBufferQueue = null;

            DIBuilder
            .Continue()

            // Add the factories for the storage proxy caches, both standard and transacted, for spatial and non spatial caches in TRex

            /////////////////////////////////////////////////////
            // Injected standard storage proxy cache factories
            /////////////////////////////////////////////////////

            .Add(x => x.AddSingleton <Func <IIgnite, StorageMutability, FileSystemStreamType, IStorageProxyCache <ISubGridSpatialAffinityKey, ISerialisedByteArrayWrapper> > >
                     (factory => (ignite, mutability, streamType) => new StorageProxyCacheTransacted_TestHarness <ISubGridSpatialAffinityKey, ISerialisedByteArrayWrapper>(ignite?.GetCache <ISubGridSpatialAffinityKey, ISerialisedByteArrayWrapper>(TRexCaches.SpatialCacheName(mutability, streamType)), new SubGridSpatialAffinityKeyEqualityComparer())))

            .Add(x => x.AddSingleton <Func <IIgnite, StorageMutability, FileSystemStreamType, IStorageProxyCache <INonSpatialAffinityKey, ISerialisedByteArrayWrapper> > >
                     (factory => (ignite, mutability, streamType) => new StorageProxyCacheTransacted_TestHarness <INonSpatialAffinityKey, ISerialisedByteArrayWrapper>(ignite?.GetCache <INonSpatialAffinityKey, ISerialisedByteArrayWrapper>(TRexCaches.NonSpatialCacheName(mutability, streamType)), new NonSpatialAffinityKeyEqualityComparer())))

            .Add(x => x.AddSingleton <Func <IIgnite, StorageMutability, FileSystemStreamType, IStorageProxyCache <ISiteModelMachineAffinityKey, ISerialisedByteArrayWrapper> > >
                     (factory => (ignite, mutability, streamType) => new StorageProxyCacheTransacted_TestHarness <ISiteModelMachineAffinityKey, ISerialisedByteArrayWrapper>(ignite?.GetCache <ISiteModelMachineAffinityKey, ISerialisedByteArrayWrapper>(TRexCaches.NonSpatialCacheName(mutability, streamType)), new SiteModelMachineAffinityKeyEqualityComparer())))

            /////////////////////////////////////////////////////
            // Injected transacted storage proxy cache factories
            /////////////////////////////////////////////////////

            .Add(x => x.AddSingleton <Func <IIgnite, StorageMutability, FileSystemStreamType, IStorageProxyCacheTransacted <ISubGridSpatialAffinityKey, ISerialisedByteArrayWrapper> > >
                     (factory => (ignite, mutability, streamType) => new StorageProxyCacheTransacted_TestHarness <ISubGridSpatialAffinityKey, ISerialisedByteArrayWrapper>(ignite?.GetCache <ISubGridSpatialAffinityKey, ISerialisedByteArrayWrapper>(TRexCaches.SpatialCacheName(mutability, streamType)), new SubGridSpatialAffinityKeyEqualityComparer())))

            .Add(x => x.AddSingleton <Func <IIgnite, StorageMutability, FileSystemStreamType, IStorageProxyCacheTransacted <INonSpatialAffinityKey, ISerialisedByteArrayWrapper> > >
                     (factory => (ignite, mutability, streamType) => new StorageProxyCacheTransacted_TestHarness <INonSpatialAffinityKey, ISerialisedByteArrayWrapper>(ignite?.GetCache <INonSpatialAffinityKey, ISerialisedByteArrayWrapper>(TRexCaches.NonSpatialCacheName(mutability, streamType)), new NonSpatialAffinityKeyEqualityComparer())))

            .Add(x => x.AddSingleton <Func <IIgnite, StorageMutability, FileSystemStreamType, IStorageProxyCacheTransacted <ISiteModelMachineAffinityKey, ISerialisedByteArrayWrapper> > >
                     (factory => (ignite, mutability, streamType) => new StorageProxyCacheTransacted_TestHarness <ISiteModelMachineAffinityKey, ISerialisedByteArrayWrapper>(ignite?.GetCache <ISiteModelMachineAffinityKey, ISerialisedByteArrayWrapper>(TRexCaches.NonSpatialCacheName(mutability, streamType)), new SiteModelMachineAffinityKeyEqualityComparer())))

            .Add(x => x.AddSingleton <Func <ITAGFileBufferQueue> >(factory => () =>
            {
                _tagFileBufferQueue ??= new TAGFileBufferQueue();
                return(_tagFileBufferQueue);
            }))

            .Build();

            // Set up a singleton storage proxy for mutable and immutable contexts for tests when there is no Ignite mock available
            var mutableStorageProxy   = new StorageProxy_Ignite_Transactional(StorageMutability.Mutable);
            var immutableStorageProxy = new StorageProxy_Ignite_Transactional(StorageMutability.Immutable);

            DIBuilder
            .Continue()

            // Add the factory to create a single storage proxy instance.
            .Add(x => x.AddSingleton <Func <StorageMutability, IStorageProxy> >(factory => mutability => mutability == StorageMutability.Mutable ? mutableStorageProxy : immutableStorageProxy))
            .Add(x => x.AddSingleton <IStorageProxyFactory>(new StorageProxyFactory()))
            .Build();
        }
Exemplo n.º 3
0
        public void Test_TAGFileBufferQueue_AddingTAGFile()
        {
            EnsureServer();

            var queue = new TAGFileBufferQueue();

            Assert.NotNull(queue);

            // Load a TAG file and add it to the queue. Verify the TAG file appears in the cache

            var tagFileName = "TestTAGFile-TAGFile-Read-Stream.tag";

            var projectUid = Guid.NewGuid();
            var assetUid   = Guid.NewGuid();

            byte[] tagContent;
            using (var tagFileStream =
                       new FileStream(Path.Combine("TestData", "TAGFiles", tagFileName),
                                      FileMode.Open, FileAccess.Read))
            {
                tagContent = new byte[tagFileStream.Length];
                tagFileStream.Read(tagContent, 0, (int)tagFileStream.Length);
            }

            var tagKey  = new TAGFileBufferQueueKey(tagFileName, projectUid, assetUid);
            var tagItem = new TAGFileBufferQueueItem
            {
                InsertUTC = DateTime.UtcNow,
                ProjectID = projectUid,
                AssetID   = assetUid,
                FileName  = tagFileName,
                Content   = tagContent
            };

            // Perform the actual add
            queue.Add(tagKey, tagItem);

            // Read it back from the cache to ensure it was added as expected.
            var queueCache = _ignite.GetCache <ITAGFileBufferQueueKey, TAGFileBufferQueueItem>(TRexCaches.TAGFileBufferQueueCacheName());

            var tagItem2 = queueCache.Get(tagKey);

            Assert.True(tagItem2 != null, "Tag item read back from buffer queue cache was null");
            Assert.True(tagItem.Content.Length == tagItem2.Content.Length, "Tag content lengths different");
            Assert.True(tagItem.InsertUTC == tagItem2.InsertUTC, "Tag insert UTCs different");
            Assert.True(tagItem.AssetID == tagItem2.AssetID, "Tag AssetUIDs different");
            Assert.True(tagItem.FileName == tagItem2.FileName, "Tag FileNames different");
            Assert.True(tagItem.ProjectID == tagItem2.ProjectID, "Tag ProjectUIDs different");
        }
Exemplo n.º 4
0
        public override void ClearDynamicFixtureContent()
        {
            base.ClearDynamicFixtureContent();

            _tagFileBufferQueue = null;
        }