/// <summary>
 /// Disposes the state reader.
 /// This operation is idempotent and can take place after an unload operation.
 /// </summary>
 public void Dispose()
 {
     if (Interlocked.Exchange(ref _disposed, 1) == 0)
     {
         _reader.Dispose();
     }
 }
 public void Dispose()
 {
     if (_isOwner)
     {
         _reader.Dispose();
     }
 }
Exemple #3
0
        public void InMemoryStorageBasicWritingReadingTest()
        {
            InMemoryStorageProvider provider = new InMemoryStorageProvider();

            string category = "someCategory";
            string itemKey  = "someItem";
            string id       = "someId";

            byte[]   buffer1 = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            byte[]   buffer2 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0 };
            byte[][] buffers = new byte[][] { buffer1, buffer2 };

            for (int i = 0; i < 2; i++)
            {
                byte[] expectedBuffer = buffers[i];

                using (IStateWriter writer =
                           i == 0 ? provider.StartNewCheckpoint(id) : provider.UpdateCheckpoint(id))
                {
                    using (Stream stream = writer.GetItemWriter(category, itemKey))
                    {
                        stream.Write(expectedBuffer, 0, expectedBuffer.Length);
                    }

                    writer.CommitAsync().Wait();
                }

                IStateReader reader = null;
                try
                {
                    if (provider.TryReadCheckpoint(out id, out reader))
                    {
                        bool success = reader.TryGetItemReader(category, itemKey, out var stream);

                        Assert.IsTrue(success, "Could not get a reader for the requested item.");
                        Assert.AreEqual(expectedBuffer.Length, stream.Length);

                        byte[] actualBuffer = new byte[expectedBuffer.Length];

                        int byteRead = stream.Read(actualBuffer, 0, actualBuffer.Length);
                        Assert.AreEqual(byteRead, stream.Length);
                        CollectionAssert.AreEqual(expectedBuffer, actualBuffer);
                    }
                }
                finally
                {
                    reader?.Dispose();
                }
            }
        }
Exemple #4
0
 protected override void DisposeCore() => _reader.Dispose();
Exemple #5
0
        public void InMemoryStorageItemDeletionTest()
        {
            InMemoryStorageProvider provider = new InMemoryStorageProvider();

            string category = "someCategory";
            string itemKey  = "someItem";
            string id       = "someId";

            byte[] buffer = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            using (IStateWriter writer = provider.StartNewCheckpoint(id))
            {
                using (Stream stream = writer.GetItemWriter(category, itemKey))
                {
                    stream.Write(buffer, 0, buffer.Length);
                }

                writer.CommitAsync().Wait();
            }

            IStateReader reader = null;

            try
            {
                if (provider.TryReadCheckpoint(out id, out reader))
                {
                    bool success = reader.TryGetItemReader(category, itemKey, out _);
                    Assert.IsTrue(success, "An stream could not be retrieved for the requested item.");
                }
                else
                {
                    Assert.Fail("Could not retrieve the checkpoint.");
                }
            }
            finally
            {
                reader?.Dispose();
            }

            using (IStateWriter writer = provider.UpdateCheckpoint(id))
            {
                writer.DeleteItem(category, itemKey);
                writer.CommitAsync().Wait();
            }

            reader = null;
            try
            {
                if (provider.TryReadCheckpoint(out id, out reader))
                {
                    bool success = reader.TryGetItemReader(category, itemKey, out _);
                    Assert.IsFalse(success, "An stream could be retrieved for the requested item.");
                }
                else
                {
                    Assert.Fail("Could not retrieve the checkpoint.");
                }
            }
            finally
            {
                reader?.Dispose();
            }
        }