Пример #1
0
        public static FileAppendOnlyStore CreateAppendOnlyStore(this FileStorageConfig cfg, string name)
        {

            var store = new FileAppendOnlyStore(new DirectoryInfo(Path.Combine(cfg.FullPath, name)));
            store.Initialize();
            return store;
        }
Пример #2
0
        public void SetUp()
        {
            _serializer = new TestMessageSerializer(new[] { typeof(TestEvent) });
            _path = Path.Combine(Path.GetTempPath(), "MessageStore", Guid.NewGuid().ToString());
            if (!Directory.Exists(_path))
                Directory.CreateDirectory(_path);
            _appendOnlyStore = new FileAppendOnlyStore(new DirectoryInfo(_path));
            _appendOnlyStore.Initialize();

            _messageStore = new MessageStore(_appendOnlyStore, _serializer);
        }
        public void get_current_version()
        {
            using (var store = new FileAppendOnlyStore(new DirectoryInfo(_storePath)))
            {
                store.Initialize();
                var currentVersion = store.GetCurrentVersion();
                store.Append("versiontest", Encoding.UTF8.GetBytes("test message1"));
                store.Append("versiontest", Encoding.UTF8.GetBytes("test message2"));
                store.Append("versiontest", Encoding.UTF8.GetBytes("test message3"));

                Assert.AreEqual(currentVersion + 3, store.GetCurrentVersion());
            }
        }
        public void append_data_when_set_version_where_does_not_correspond_real_version()
        {
            var key = Guid.NewGuid().ToString();

            using (var store = new FileAppendOnlyStore(new DirectoryInfo(_storePath)))
            {
                store.Initialize();
                store.Append(key, Encoding.UTF8.GetBytes("test message1"), 100);

                var data = store.ReadRecords(key, -1, 2).ToArray();
                CollectionAssert.IsEmpty(data);
            }
        }
        public void SetUp()
        {
            _storeRecords = new List<StoreRecord>();
            _serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), typeof(string) });
            _path = Path.Combine(Path.GetTempPath(), "MessageStorePublisher", Guid.NewGuid().ToString());
            _appendOnlyStore = new FileAppendOnlyStore(new DirectoryInfo(_path));
            _appendOnlyStore.Initialize();
            _store = new MessageStore(_appendOnlyStore, _serializer);
            var streamer = new EnvelopeStreamer(_serializer);
            var queueWriter = new TestQueueWriter();
            _sender = new MessageSender(streamer, queueWriter);
            var store = new FileDocumentStore(Path.Combine(_path, "lokad-cqrs-test"), new DocumentStrategy());
            _nuclearStorage = new NuclearStorage(store);

            _publisher = new MessageStorePublisher(_store, _sender, _nuclearStorage, DoWePublishThisRecord);
        }
Пример #6
0
        public void SetUp()
        {
            _serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), typeof(string) });
            _path = Path.Combine(Path.GetTempPath(), "MessageStore", Guid.NewGuid().ToString());
            if (!Directory.Exists(_path))
                Directory.CreateDirectory(_path);
            _appendOnlyStore = new FileAppendOnlyStore(new DirectoryInfo(_path));

            var store = new MessageStore(_appendOnlyStore, _serializer);
            store.AppendToStore("stream1", MessageAttribute.Empty, -1, new[] { new SerializerTest1("msg1") });
            store.AppendToStore("stream2", MessageAttribute.Empty, -1, new[] { new SerializerTest1("msg1"), new SerializerTest1("msg2") });
            store.AppendToStore("stream3", MessageAttribute.Empty, -1, new[] { new SerializerTest1("msg1"), new SerializerTest1("msg2"), new SerializerTest1("msg3") });
            store.RecordMessage("stream4", new ImmutableEnvelope("EnvId", DateTime.UtcNow, new SerializerTest1("msg1"), MessageAttribute.Empty));

            _appendOnlyStore.Close();
            _appendOnlyStore = new FileAppendOnlyStore(new DirectoryInfo(_path));
            _appendOnlyStore.Initialize();

            _store = new MessageStore(_appendOnlyStore, _serializer);
        }
        public void load_cache()
        {
            CreateCacheFiles();
            using (var store = new FileAppendOnlyStore(new DirectoryInfo(_storePath)))
            {
                store.LoadCaches();

                for (int j = 0; j < DataFileCount; j++)
                {
                    var key = "test-key" + j;
                    var data = store.ReadRecords(key, -1, Int32.MaxValue);

                    int i = 0;
                    foreach (var dataWithKey in data)
                    {
                        Assert.AreEqual("test messages" + i, Encoding.UTF8.GetString(dataWithKey.Data));
                        i++;
                    }
                    Assert.AreEqual(FileMessagesCount, i);
                }
            }
        }
        public void append_data()
        {
            using (var store = new FileAppendOnlyStore(new DirectoryInfo(_storePath)))
            {
                store.Initialize();
                var currentVersion = store.GetCurrentVersion();
                const int messagesCount = 3;
                for (int i = 0; i < messagesCount; i++)
                {
                    store.Append("stream1", Encoding.UTF8.GetBytes("test message" + i));
                }

                var data = store.ReadRecords("stream1", currentVersion, Int32.MaxValue).ToArray();

                for (int i = 0; i < messagesCount; i++)
                {
                    Assert.AreEqual("test message" + i, Encoding.UTF8.GetString(data[i].Data));
                }

                Assert.AreEqual(messagesCount, data.Length);
            }
        }
        public void read_store_records_after_version()
        {
            var stream = Guid.NewGuid().ToString();
            using (var store = new FileAppendOnlyStore(new DirectoryInfo(_storePath)))
            {
                store.Initialize();
                var currentVersion = store.GetCurrentVersion();
                for (int i = 0; i < 2; i++)
                    store.Append(stream, Encoding.UTF8.GetBytes("test message" + i));

                var records = store.ReadRecords(currentVersion+1, Int32.MaxValue).ToArray();

                Assert.AreEqual(1, records.Length);
                Assert.AreEqual("test message1" , Encoding.UTF8.GetString(records[0].Data));
                Assert.AreEqual(2, records[0].StreamVersion);
                Assert.AreEqual(currentVersion+2, records[0].StoreVersion);
            }
        }
Пример #10
0
        public void read_all_records_by_stream()
        {
            var stream = Guid.NewGuid().ToString();

            using (var store = new FileAppendOnlyStore(new DirectoryInfo(_storePath)))
            {
                store.Initialize();
                for (int i = 0; i < 2; i++)
                    store.Append(stream, Encoding.UTF8.GetBytes("test message" + i));

                var records = store.ReadRecords(stream, -1, Int32.MaxValue).ToArray();

                Assert.AreEqual(2, records.Length);

                for (int i = 0; i < 2; i++)
                {
                    Assert.AreEqual("test message" + i, Encoding.UTF8.GetString(records[i].Data));
                    Assert.AreEqual(i + 1, records[i].StreamVersion);
                }
            }
        }
Пример #11
0
        public void load_cache_when_incorrect_data_file()
        {
            var currentPath = Path.Combine(_storePath, "EmptyCache");
            Directory.CreateDirectory(currentPath);
            var store = new FileAppendOnlyStore(new DirectoryInfo(currentPath));

            //write frame
            using (var stream = new FileStream(Path.Combine(currentPath, "0.dat"), FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite))
                StorageFramesEvil.WriteFrame("test-key", 0, Encoding.UTF8.GetBytes("test message"), stream);

            //write incorrect frame
            using (var sw = new StreamWriter(Path.Combine(currentPath, "1.dat")))
                sw.Write("incorrect frame data");

            store.LoadCaches();
            var data = store.ReadRecords(0, Int32.MaxValue).ToArray();

            Assert.AreEqual(1, data.Length);
            Assert.AreEqual("test-key", data[0].Key);
            Assert.AreEqual(0, data[0].StreamVersion);
            Assert.AreEqual("test message", Encoding.UTF8.GetString(data[0].Data));
            Assert.IsTrue(File.Exists(Path.Combine(currentPath, "1.dat")));
        }
 public void Setup()
 {
     _store = new FileAppendOnlyStore(new DirectoryInfo(_storePath));
 }