예제 #1
0
        public void Setup()
        {
            Config.Set("object-store-root", TestStorageRoot);

            _store = new LocalObjectStore();
            _store.Initialize("CSharp-TestAlgorithm", 0, 0, "", new Controls());
        }
예제 #2
0
        public void DeletedObjectIsNotReloaded()
        {
            using (var store = new LocalObjectStore())
            {
                store.Initialize("test", 0, 0, "", new Controls());
                Assert.IsTrue(Directory.Exists("./LocalObjectStoreTests/test"));

                var validData = new byte[1024 * 4];
                store.SaveBytes("a.txt", validData);
                Assert.IsTrue(store.ContainsKey("a.txt"));

                store.SaveBytes("b.txt", validData);
                Assert.IsTrue(store.ContainsKey("b.txt"));

                // Assert the store has our two objects
                var storedObj = store.GetEnumerator().AsEnumerable().ToList();
                Assert.IsTrue(storedObj.Count == 2);

                // Delete a.txt and close this store down
                store.Delete("a.txt");
                Assert.IsFalse(store.ContainsKey("a.txt"));
            }

            using (var store = new LocalObjectStore())
            {
                // Check that the dir still exists, it had files so it shouldn't have deleted
                Assert.IsTrue(Directory.Exists("./LocalObjectStoreTests/test"));
                store.Initialize("test", 0, 0, "", new Controls());

                // Check our files; a should be gone, b should be there
                Assert.IsFalse(store.ContainsKey("a.txt"));
                Assert.IsTrue(store.ContainsKey("b.txt"));
            }
        }
예제 #3
0
        public void DisposeRemovesEmptyStorageFolder()
        {
            using (var store = new LocalObjectStore())
            {
                store.Initialize("unused", 0, 0, "", new Controls());

                Assert.IsTrue(Directory.Exists("./LocalObjectStoreTests/unused"));
            }

            Assert.IsFalse(Directory.Exists("./LocalObjectStoreTests/unused"));
        }
예제 #4
0
        public async Task NormalRead()
        {
            _subSecretStore.ReadAsync(ServiceInstanceKey).Returns(SampleUtils.GetSampleContent(ServiceInstanceSampleFile));

            LocalObjectStore      localObjectStore = CreateLocalObjectStore();
            HealthServiceInstance serviceInstance  = await localObjectStore.ReadAsync <HealthServiceInstance>(ServiceInstanceKey);

            Assert.AreEqual("test", serviceInstance.Id);
            Assert.AreEqual("Test", serviceInstance.Name);
            Assert.AreEqual("description", serviceInstance.Description);
            Assert.AreEqual(new Uri("http://contoso.com"), serviceInstance.HealthServiceUrl);
            Assert.AreEqual(new Uri("http://contoso.com/shell"), serviceInstance.ShellUrl);
        }
예제 #5
0
        public void DisposeDoesNotErrorWhenStorageFolderAlreadyDeleted()
        {
            var testHandler = new QueueLogHandler();

            Log.LogHandler = testHandler;

            using (var store = new LocalObjectStore())
            {
                store.Initialize("unused", 0, 0, "", new Controls());

                Directory.Delete("./LocalObjectStoreTests/unused");
            }

            Assert.IsFalse(testHandler.Logs.Any(message =>
                                                message.Message.Contains("Error deleting storage directory.")));
        }
예제 #6
0
        public async Task NormalWrite()
        {
            var serviceInstance = new HealthServiceInstance
            {
                Id               = "test",
                Name             = "Test",
                Description      = "description",
                HealthServiceUrl = new Uri("http://contoso.com"),
                ShellUrl         = new Uri("http://contoso.com/shell"),
            };

            LocalObjectStore localObjectStore = CreateLocalObjectStore();
            await localObjectStore.WriteAsync(ServiceInstanceKey, serviceInstance);

            await _subSecretStore.Received().WriteAsync(ServiceInstanceKey, SampleUtils.GetSampleContent(ServiceInstanceSampleFile));
        }
예제 #7
0
        public void DisposeDoesNotDeleteStoreFiles()
        {
            string path;

            using (var store = new LocalObjectStore())
            {
                store.Initialize("test", 0, 0, "", new Controls()
                {
                    PersistenceIntervalSeconds = -1
                });
                Assert.IsTrue(Directory.Exists("./LocalObjectStoreTests/test"));

                var validData = new byte[1024 * 1024 * 4];
                var saved     = store.SaveBytes("a.txt", validData);
                Assert.IsTrue(saved);

                path = store.GetFilePath("a.txt");
                Assert.IsTrue(File.Exists(path));
            }

            // Check that it still exists
            Assert.IsTrue(File.Exists(path));
        }