Skip to content
This repository
Browse code

EventStore source code

  • Loading branch information...
commit 1b4764bc13fa6cba6b7e2c22ded6a8c61c91bad8 0 parents
Yuriy Solodkyy ysw authored

Showing 886 changed files with 25,453 additions and 0 deletions. Show diff stats Hide diff stats

  1. +9 0 LICENSE
  2. +11 0 src/.gitignore
  3. +143 0 src/EventStore/EventStore.BufferManagement.Tests/BufferManagerTests.cs
  4. +149 0 src/EventStore/EventStore.BufferManagement.Tests/BufferPoolStreamTests.cs
  5. +555 0 src/EventStore/EventStore.BufferManagement.Tests/BufferPoolTests.cs
  6. +73 0 src/EventStore/EventStore.BufferManagement.Tests/EventStore.BufferManagement.Tests.csproj
  7. +66 0 src/EventStore/EventStore.BufferManagement.Tests/Properties/AssemblyInfo.cs
  8. +267 0 src/EventStore/EventStore.BufferManagement/BufferManager.cs
  9. +351 0 src/EventStore/EventStore.BufferManagement/BufferPool.cs
  10. +94 0 src/EventStore/EventStore.BufferManagement/BufferPoolStream.cs
  11. +73 0 src/EventStore/EventStore.BufferManagement/EventStore.BufferManagement.csproj
  12. +67 0 src/EventStore/EventStore.BufferManagement/Properties/AssemblyInfo.cs
  13. +39 0 src/EventStore/EventStore.BufferManagement/UnableToAllocateBufferException.cs
  14. +39 0 src/EventStore/EventStore.BufferManagement/UnableToCreateMemoryException.cs
  15. +115 0 src/EventStore/EventStore.Client/Commands/CreateStreamProcessor.cs
  16. +115 0 src/EventStore/EventStore.Client/Commands/DeleteProcessor.cs
  17. +180 0 src/EventStore/EventStore.Client/Commands/DvuAdvanced/Coordinator.cs
  18. +197 0 src/EventStore/EventStore.Client/Commands/DvuAdvanced/DvuAdvancedProcessor.cs
  19. +34 0 src/EventStore/EventStore.Client/Commands/DvuAdvanced/IProducer.cs
  20. +108 0 src/EventStore/EventStore.Client/Commands/DvuAdvanced/VerificationEvent.cs
  21. +62 0 src/EventStore/EventStore.Client/Commands/DvuAdvanced/Workers/BankAccountProducer.cs
  22. +54 0 src/EventStore/EventStore.Client/Commands/DvuAdvanced/Workers/TestProducer.cs
  23. +132 0 src/EventStore/EventStore.Client/Commands/DvuAdvanced/Workers/VerificationWorker.cs
  24. +280 0 src/EventStore/EventStore.Client/Commands/DvuAdvanced/Workers/Worker.cs
  25. +51 0 src/EventStore/EventStore.Client/Commands/DvuAdvanced/Workers/WorkerItem.cs
  26. +135 0 src/EventStore/EventStore.Client/Commands/DvuAdvanced/Workers/WriteWorker.cs
  27. +299 0 src/EventStore/EventStore.Client/Commands/DvuBasic/BankAccountBasicProducer.cs
  28. +77 0 src/EventStore/EventStore.Client/Commands/DvuBasic/BankAccountEventFactory.cs
  29. +476 0 src/EventStore/EventStore.Client/Commands/DvuBasic/DvuBasicProcessor.cs
  30. +39 0 src/EventStore/EventStore.Client/Commands/DvuBasic/IBasicProducer.cs
  31. +110 0 src/EventStore/EventStore.Client/Commands/DvuBasic/Status.cs
  32. +44 0 src/EventStore/EventStore.Client/Commands/DvuBasic/StreamNamesGenerator.cs
  33. +46 0 src/EventStore/EventStore.Client/Commands/ExitProcessor.cs
  34. +193 0 src/EventStore/EventStore.Client/Commands/MultiWriteFloodWaiting.cs
  35. +125 0 src/EventStore/EventStore.Client/Commands/MultiWriteProcessor.cs
  36. +162 0 src/EventStore/EventStore.Client/Commands/PingFloodHttpProcessor.cs
  37. +153 0 src/EventStore/EventStore.Client/Commands/PingFloodProcessor.cs
  38. +139 0 src/EventStore/EventStore.Client/Commands/PingFloodWaitingProcessor.cs
  39. +210 0 src/EventStore/EventStore.Client/Commands/PingHttpLongTermProcessor.cs
  40. +72 0 src/EventStore/EventStore.Client/Commands/PingProcessor.cs
  41. +152 0 src/EventStore/EventStore.Client/Commands/ReadFloodHttpProcessor.cs
  42. +173 0 src/EventStore/EventStore.Client/Commands/ReadFloodProcessor.cs
  43. +77 0 src/EventStore/EventStore.Client/Commands/ReadHttpProcessor.cs
  44. +123 0 src/EventStore/EventStore.Client/Commands/ReadProcessor.cs
  45. +88 0 src/EventStore/EventStore.Client/Commands/SubscribeToStreamProcessor.cs
  46. +206 0 src/EventStore/EventStore.Client/Commands/TransactionWriteProcessor.cs
  47. +51 0 src/EventStore/EventStore.Client/Commands/UsageProcessor.cs
  48. +183 0 src/EventStore/EventStore.Client/Commands/WriteFloodHttpProcessor.cs
  49. +235 0 src/EventStore/EventStore.Client/Commands/WriteFloodProcessor.cs
  50. +183 0 src/EventStore/EventStore.Client/Commands/WriteFloodWaitingHttpProcessor.cs
  51. +184 0 src/EventStore/EventStore.Client/Commands/WriteFloodWaitingProcessor.cs
  52. +98 0 src/EventStore/EventStore.Client/Commands/WriteHttpProcessor.cs
  53. +260 0 src/EventStore/EventStore.Client/Commands/WriteLongTermHttpProcessor.cs
  54. +255 0 src/EventStore/EventStore.Client/Commands/WriteLongTermProcessor.cs
  55. +126 0 src/EventStore/EventStore.Client/Commands/WriteProcessor.cs
  56. +167 0 src/EventStore/EventStore.Client/EventStore.Client.csproj
  57. +63 0 src/EventStore/EventStore.Client/Properties/AssemblyInfo.cs
  58. +142 0 src/EventStore/EventStore.ClientAPI/Commands/CreateStreamCompletionWrapper.cs
  59. +131 0 src/EventStore/EventStore.ClientAPI/Commands/DeleteTaskCompletionWrapper.cs
  60. +44 0 src/EventStore/EventStore.ClientAPI/Commands/ITaskCompletionWrapper.cs
  61. +23 0 src/EventStore/EventStore.ClientAPI/Commands/ProcessResultStatus.cs
  62. +107 0 src/EventStore/EventStore.ClientAPI/Commands/ReadFromBeginningTaskCompletionWrapper.cs
  63. +130 0 src/EventStore/EventStore.ClientAPI/Commands/WriteTaskCompletionWrapper.cs
  64. +439 0 src/EventStore/EventStore.ClientAPI/Common/ConcurrentCollections/ConcurrentQueue.cs
  65. +439 0 src/EventStore/EventStore.ClientAPI/Common/ConcurrentCollections/ConcurrentStack.cs
  66. +67 0 src/EventStore/EventStore.ClientAPI/Common/Log/LogManager.cs
  67. +16 0 src/EventStore/EventStore.ClientAPI/Common/Log/Logger.cs
  68. +117 0 src/EventStore/EventStore.ClientAPI/Common/Utils/BytesFormatter.cs
  69. +82 0 src/EventStore/EventStore.ClientAPI/Common/Utils/Ensure.cs
  70. +71 0 src/EventStore/EventStore.ClientAPI/Configure.cs
  71. +58 0 src/EventStore/EventStore.ClientAPI/Data/Event.cs
  72. +184 0 src/EventStore/EventStore.ClientAPI/Data/EventRecord.cs
  73. +36 0 src/EventStore/EventStore.ClientAPI/Data/ExpectedVersion.cs
  74. +140 0 src/EventStore/EventStore.ClientAPI/EventStore.ClientAPI.csproj
  75. +116 0 src/EventStore/EventStore.ClientAPI/EventStore.cs
  76. +461 0 src/EventStore/EventStore.ClientAPI/EventStoreConnection.cs
  77. +52 0 src/EventStore/EventStore.ClientAPI/EventStream.cs
  78. +40 0 src/EventStore/EventStore.ClientAPI/Exceptions/ConnectionClosingException.cs
  79. +43 0 src/EventStore/EventStore.ClientAPI/Exceptions/FailedConnectionException.cs
  80. +40 0 src/EventStore/EventStore.ClientAPI/Exceptions/UnknownPackageReturned.cs
  81. +718 0 src/EventStore/EventStore.ClientAPI/Messages/ClientMessageDto.cs
  82. +40 0 src/EventStore/EventStore.ClientAPI/Messages/OperationErrorCode.cs
  83. +63 0 src/EventStore/EventStore.ClientAPI/Properties/AssemblyInfo.cs
  84. +69 0 src/EventStore/EventStore.ClientAPI/Results.cs
  85. +44 0 src/EventStore/EventStore.ClientAPI/Services.Storage.ReadIndex/ReadResult.cs
  86. +79 0 src/EventStore/EventStore.ClientAPI/Services.Transport.Tcp/TcpCommand.cs
  87. +78 0 src/EventStore/EventStore.ClientAPI/Services.Transport.Tcp/TcpPackage.cs
  88. +122 0 src/EventStore/EventStore.ClientAPI/TcpConnector.cs
  89. +152 0 src/EventStore/EventStore.ClientAPI/TransactionLog.LogRecords/CommitLogRecord.cs
  90. +130 0 src/EventStore/EventStore.ClientAPI/TransactionLog.LogRecords/LogRecord.cs
  91. +35 0 src/EventStore/EventStore.ClientAPI/TransactionLog.LogRecords/LogRecordType.cs
  92. +252 0 src/EventStore/EventStore.ClientAPI/TransactionLog.LogRecords/PrepareLogRecord.cs
  93. +56 0 src/EventStore/EventStore.ClientAPI/Transport.Tcp/IMonitoredTcpConnection.cs
  94. +45 0 src/EventStore/EventStore.ClientAPI/Transport.Tcp/ITcpConnection.cs
  95. +135 0 src/EventStore/EventStore.ClientAPI/Transport.Tcp/LengthPrefixFramer.cs
  96. +64 0 src/EventStore/EventStore.ClientAPI/Transport.Tcp/ProtobufExtensions.cs
  97. +86 0 src/EventStore/EventStore.ClientAPI/Transport.Tcp/SocketArgsPool.cs
  98. +155 0 src/EventStore/EventStore.ClientAPI/Transport.Tcp/TcpClientConnector.cs
  99. +44 0 src/EventStore/EventStore.ClientAPI/Transport.Tcp/TcpConfiguratin.cs
  100. +476 0 src/EventStore/EventStore.ClientAPI/Transport.Tcp/TcpConnection.cs
  101. +317 0 src/EventStore/EventStore.ClientAPI/Transport.Tcp/TcpConnectionBase.cs
  102. +324 0 src/EventStore/EventStore.ClientAPI/Transport.Tcp/TcpConnectionMonitor.cs
  103. +109 0 src/EventStore/EventStore.ClientAPI/Transport.Tcp/TcpTypedConnection.cs
  104. +274 0 src/EventStore/EventStore.ClientAPI/Usage.cs
  105. +61 0 src/EventStore/EventStore.Common/CommandLine/EventStoreCmdLineOptionsBase.cs
  106. +2,131 0 src/EventStore/EventStore.Common/CommandLine/lib/CommandLine.cs
  107. +1,374 0 src/EventStore/EventStore.Common/CommandLine/lib/CommandLineText.cs
  108. +439 0 src/EventStore/EventStore.Common/ConcurrentCollections/ConcurrentQueue.cs
  109. +439 0 src/EventStore/EventStore.Common/ConcurrentCollections/ConcurrentStack.cs
  110. +35 0 src/EventStore/EventStore.Common/Configuration/Constants.cs
  111. +87 0 src/EventStore/EventStore.Common/EventStore.Common.csproj
  112. +40 0 src/EventStore/EventStore.Common/Exceptions/ApplicationInitializationException.cs
  113. +58 0 src/EventStore/EventStore.Common/Log/ILogger.cs
  114. +143 0 src/EventStore/EventStore.Common/Log/LazyLogger.cs
  115. +115 0 src/EventStore/EventStore.Common/Log/LogManager.cs
  116. +145 0 src/EventStore/EventStore.Common/Log/NLogger.cs
  117. +63 0 src/EventStore/EventStore.Common/Properties/AssemblyInfo.cs
  118. +43 0 src/EventStore/EventStore.Common/Settings/ApplicationSettings.cs
  119. +57 0 src/EventStore/EventStore.Common/Settings/VNodeSettings.cs
  120. +68 0 src/EventStore/EventStore.Common/Utils/Application.cs
  121. +118 0 src/EventStore/EventStore.Common/Utils/BytesFormatter.cs
  122. +82 0 src/EventStore/EventStore.Common/Utils/Ensure.cs
  123. +52 0 src/EventStore/EventStore.Common/Utils/EnumerableExtensions.cs
  124. +51 0 src/EventStore/EventStore.Common/Utils/Helper.cs
  125. +51 0 src/EventStore/EventStore.Common/Utils/IPEndpointExtensions.cs
  126. +53 0 src/EventStore/EventStore.Common/Utils/OS.cs
  127. +39 0 src/EventStore/EventStore.Common/Utils/Runtime.cs
  128. +49 0 src/EventStore/EventStore.Core.Tests/Bus/Helpers/BusTestBase.cs
  129. +140 0 src/EventStore/EventStore.Core.Tests/Bus/Helpers/BusTestHandlers.cs
  130. +48 0 src/EventStore/EventStore.Core.Tests/Bus/Helpers/BusTestMessages.cs
  131. +57 0 src/EventStore/EventStore.Core.Tests/Bus/Helpers/TimeoutHelper.cs
  132. +96 0 src/EventStore/EventStore.Core.Tests/Bus/QueuedHandler/Helpers/Consumers.cs
  133. +49 0 src/EventStore/EventStore.Core.Tests/Bus/QueuedHandler/Helpers/Messages.cs
  134. +79 0 src/EventStore/EventStore.Core.Tests/Bus/QueuedHandler/Helpers/QueuedHandlerTestBase.cs
  135. +49 0 src/EventStore/EventStore.Core.Tests/Bus/QueuedHandler/queued_handler_should.cs
  136. +160 0 src/EventStore/EventStore.Core.Tests/Bus/QueuedHandler/when_publishing.cs
  137. +100 0 src/EventStore/EventStore.Core.Tests/Bus/QueuedHandler/when_publishing_before_starting.cs
  138. +68 0 src/EventStore/EventStore.Core.Tests/Bus/QueuedHandler/when_starting.cs
  139. +111 0 src/EventStore/EventStore.Core.Tests/Bus/QueuedHandler/when_stopping.cs
  140. +165 0 src/EventStore/EventStore.Core.Tests/Bus/when_publishing.cs
  141. +193 0 src/EventStore/EventStore.Core.Tests/Bus/when_subscribing.cs
  142. +198 0 src/EventStore/EventStore.Core.Tests/Bus/when_unsubscribing.cs
  143. +71 0 src/EventStore/EventStore.Core.Tests/Common/CollectionsExtensions.cs
  144. +49 0 src/EventStore/EventStore.Core.Tests/Common/HelperExtensions.cs
  145. +162 0 src/EventStore/EventStore.Core.Tests/DataStructures/pairing_heap_should.cs
  146. +242 0 src/EventStore/EventStore.Core.Tests/EventStore.Core.Tests.csproj
  147. +188 0 src/EventStore/EventStore.Core.Tests/EventStore.Core.Tests.csproj.orig
  148. +118 0 src/EventStore/EventStore.Core.Tests/Fakes/FakeLogger.cs
  149. +48 0 src/EventStore/EventStore.Core.Tests/Fakes/FakePublisher.cs
  150. +40 0 src/EventStore/EventStore.Core.Tests/Fakes/NoopPublisher.cs
  151. +51 0 src/EventStore/EventStore.Core.Tests/Index/FakeFilenameProvider.cs
  152. +68 0 src/EventStore/EventStore.Core.Tests/Index/IndexEntryTests.cs
  153. +664 0 src/EventStore/EventStore.Core.Tests/Index/MemTableTests.cs
  154. +67 0 src/EventStore/EventStore.Core.Tests/Index/PTableReadScenario.cs
  155. +54 0 src/EventStore/EventStore.Core.Tests/Index/ReverseComparerTests.cs
  156. +117 0 ...EventStore.Core.Tests/Index/adding_four_items_to_empty_index_map_with_four_tables_per_level_causes_merge.cs
  157. +114 0 ...tore.Core.Tests/Index/adding_four_items_to_empty_index_map_with_two_tables_per_level_causes_double_merge.cs
  158. +110 0 src/EventStore/EventStore.Core.Tests/Index/adding_item_to_empty_index_map.cs
  159. +139 0 ....Core.Tests/Index/adding_sixteen_items_to_empty_index_map_with_four_tables_per_level_causes_double_merge.cs
  160. +109 0 ...e/EventStore.Core.Tests/Index/adding_two_items_to_empty_index_map_with_two_tables_per_level_causes_merge.cs
  161. +69 0 src/EventStore/EventStore.Core.Tests/Index/create_index_map_from_non_existing_file.cs
  162. +69 0 src/EventStore/EventStore.Core.Tests/Index/destroying_ptable.cs
  163. +163 0 src/EventStore/EventStore.Core.Tests/Index/index_map_should.cs
  164. +239 0 src/EventStore/EventStore.Core.Tests/Index/index_map_should_detect_corruption.cs
  165. +183 0 src/EventStore/EventStore.Core.Tests/Index/ptable_range_query_tests.cs
Sorry, we could not display the entire diff because too many files (886) changed.
9 LICENSE
... ... @@ -0,0 +1,9 @@
  1 +Copyright (c) 2012, Event Store LLP
  2 +All rights reserved.
  3 +
  4 +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  5 +
  6 +Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  7 +Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  8 +Neither the name of Event Store LLP nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  9 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 src/.gitignore
... ... @@ -0,0 +1,11 @@
  1 +/Logs
  2 +/Data
  3 +/v8/
  4 +ipch/
  5 +*.o
  6 +*.ii
  7 +*.s
  8 +*.sdf
  9 +*.opensdf
  10 +*.DotSettings.user
  11 +*.DotSettings.personal
143 src/EventStore/EventStore.BufferManagement.Tests/BufferManagerTests.cs
... ... @@ -0,0 +1,143 @@
  1 +// Copyright (c) 2012, Event Store LLP
  2 +// All rights reserved.
  3 +//
  4 +// Redistribution and use in source and binary forms, with or without
  5 +// modification, are permitted provided that the following conditions are
  6 +// met:
  7 +//
  8 +// Redistributions of source code must retain the above copyright notice,
  9 +// this list of conditions and the following disclaimer.
  10 +// Redistributions in binary form must reproduce the above copyright
  11 +// notice, this list of conditions and the following disclaimer in the
  12 +// documentation and/or other materials provided with the distribution.
  13 +// Neither the name of the Event Store LLP nor the names of its
  14 +// contributors may be used to endorse or promote products derived from
  15 +// this software without specific prior written permission
  16 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  20 +// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27 +//
  28 +using System;
  29 +using NUnit.Framework;
  30 +
  31 +namespace EventStore.BufferManagement.Tests
  32 +{
  33 + [TestFixture]
  34 + public class when_creating_a_buffer_manager
  35 + {
  36 + [Test, ExpectedException(typeof(ArgumentException))]
  37 + public void a_zero_chunk_size_causes_an_argumentexception()
  38 + {
  39 + BufferManager manager = new BufferManager(1024, 0, 1024);
  40 + }
  41 +
  42 + [Test, ExpectedException(typeof(ArgumentException))]
  43 + public void a_negative_chunk_size_causes_an_argumentexception()
  44 + {
  45 + BufferManager manager = new BufferManager(200, -1, 200);
  46 + }
  47 +
  48 + [Test, ExpectedException(typeof(ArgumentException))]
  49 + public void a_negative_chunks_per_segment_causes_an_argumentexception()
  50 + {
  51 + BufferManager manager = new BufferManager(-1, 1024, 8);
  52 + }
  53 +
  54 + [Test, ExpectedException(typeof(ArgumentException))]
  55 + public void a_zero_chunks_per_segment_causes_an_argumentexception()
  56 + {
  57 + BufferManager manager = new BufferManager(0, 1024, 8);
  58 + }
  59 +
  60 + [Test, ExpectedException(typeof(ArgumentException))]
  61 + public void a_negative_number_of_segments_causes_an_argumentexception()
  62 + {
  63 + BufferManager manager = new BufferManager(1024, 1024, -1);
  64 + }
  65 +
  66 + [Test]
  67 + public void can_create_a_manager_with_zero_inital_segments()
  68 + {
  69 + BufferManager manager = new BufferManager(1024, 1024, 0);
  70 + }
  71 + }
  72 +
  73 + [TestFixture]
  74 + public class when_checking_out_a_buffer
  75 + {
  76 + [Test]
  77 + public void should_return_a_valid_buffer_when_available()
  78 + {
  79 + BufferManager manager = new BufferManager(1, 1000, 1);
  80 + ArraySegment<byte> buffer = manager.CheckOut();
  81 + Assert.AreEqual(1000, buffer.Count);
  82 + }
  83 +
  84 + [Test]
  85 + public void should_decrement_available_buffers()
  86 + {
  87 + BufferManager manager = new BufferManager(1, 1000, 1);
  88 + ArraySegment<byte> buffer = manager.CheckOut();
  89 + Assert.AreEqual(0, manager.AvailableBuffers);
  90 + }
  91 +
  92 + [Test]
  93 + public void should_create_a_segment_if_none_are_availabke()
  94 + {
  95 + BufferManager manager = new BufferManager(10, 1000, 0);
  96 + ArraySegment<byte> buffer = manager.CheckOut();
  97 + Assert.AreEqual(9, manager.AvailableBuffers);
  98 + }
  99 +
  100 + [Test, ExpectedException(typeof(UnableToCreateMemoryException))]
  101 + public void should_throw_an_unabletocreatememoryexception_if_acquiring_memory_is_disabled_and_out_of_memory()
  102 + {
  103 + BufferManager manager = new BufferManager(1, 1000, 1, false);
  104 + ArraySegment<byte> buffer = manager.CheckOut();
  105 + //should be none left, boom
  106 + manager.CheckOut();
  107 + }
  108 + }
  109 +
  110 + [TestFixture]
  111 + public class when_checking_in_a_buffer
  112 + {
  113 + [Test]
  114 + public void should_accept_a_checked_out_buffer()
  115 + {
  116 + BufferManager manager = new BufferManager(10, 1000, 0);
  117 + manager.CheckIn(manager.CheckOut());
  118 + }
  119 +
  120 + [Test]
  121 + public void should_increment_available_buffers()
  122 + {
  123 + BufferManager manager = new BufferManager(10, 1000, 0);
  124 + manager.CheckIn(manager.CheckOut());
  125 + Assert.AreEqual(10, manager.AvailableBuffers);
  126 + }
  127 +
  128 + [Test, ExpectedException(typeof(ArgumentNullException))]
  129 + public void should_throw_argumentnullexception_if_null_buffer()
  130 + {
  131 + BufferManager manager = new BufferManager(10, 1000, 0);
  132 + manager.CheckIn(null);
  133 + }
  134 +
  135 + [Test, ExpectedException(typeof(ArgumentException))]
  136 + public void should_throw_argumentexception_if_buffer_wrong_size()
  137 + {
  138 + BufferManager manager = new BufferManager(10, 1000, 0);
  139 + byte[] data = new byte[10000];
  140 + manager.CheckIn(new ArraySegment<byte>(data));
  141 + }
  142 + }
  143 +}
149 src/EventStore/EventStore.BufferManagement.Tests/BufferPoolStreamTests.cs
... ... @@ -0,0 +1,149 @@
  1 +// Copyright (c) 2012, Event Store LLP
  2 +// All rights reserved.
  3 +//
  4 +// Redistribution and use in source and binary forms, with or without
  5 +// modification, are permitted provided that the following conditions are
  6 +// met:
  7 +//
  8 +// Redistributions of source code must retain the above copyright notice,
  9 +// this list of conditions and the following disclaimer.
  10 +// Redistributions in binary form must reproduce the above copyright
  11 +// notice, this list of conditions and the following disclaimer in the
  12 +// documentation and/or other materials provided with the distribution.
  13 +// Neither the name of the Event Store LLP nor the names of its
  14 +// contributors may be used to endorse or promote products derived from
  15 +// this software without specific prior written permission
  16 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  20 +// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27 +//
  28 +using System;
  29 +using System.IO;
  30 +using NUnit.Framework;
  31 +
  32 +namespace EventStore.BufferManagement.Tests
  33 +{
  34 + public class has_buffer_pool_fixture : has_buffer_manager_fixture
  35 + {
  36 + protected BufferPool BufferPool;
  37 + [SetUp]
  38 + public override void Setup()
  39 + {
  40 + base.Setup();
  41 + BufferPool = new BufferPool(10, BufferManager);
  42 + }
  43 + }
  44 +
  45 + [TestFixture]
  46 + public class when_insantiating_a_buffer_pool_stream : has_buffer_pool_fixture
  47 + {
  48 + [Test, ExpectedException(typeof(ArgumentNullException))]
  49 + public void a_null_buffer_pool_throws_an_argumentnullexception()
  50 + {
  51 + BufferPoolStream stream = new BufferPoolStream(null);
  52 + }
  53 +
  54 + [Test]
  55 + public void the_internal_buffer_pool_is_set()
  56 + {
  57 + BufferPoolStream stream = new BufferPoolStream(BufferPool);
  58 + Assert.AreEqual(BufferPool, stream.BufferPool);
  59 + }
  60 +
  61 + }
  62 +
  63 + [TestFixture]
  64 + public class when_reading_from_the_stream : has_buffer_pool_fixture
  65 + {
  66 + [Test]
  67 + public void position_is_incremented()
  68 + {
  69 + BufferPoolStream stream = new BufferPoolStream(BufferPool);
  70 + stream.Write(new byte[500], 0, 500);
  71 + stream.Seek(0, SeekOrigin.Begin);
  72 + Assert.AreEqual(0, stream.Position);
  73 + int read = stream.Read(new byte[50], 0, 50);
  74 + Assert.AreEqual(50, stream.Position);
  75 + }
  76 +
  77 + [Test]
  78 + public void a_read_past_the_end_of_the_stream_returns_zero()
  79 + {
  80 + BufferPoolStream stream = new BufferPoolStream(BufferPool);
  81 + stream.Write(new byte[500], 0, 500);
  82 + stream.Position = 0;
  83 + int read = stream.Read(new byte[500], 0, 500);
  84 + Assert.AreEqual(500, read);
  85 + read = stream.Read(new byte[500], 0, 500);
  86 + Assert.AreEqual(0, read);
  87 + }
  88 + }
  89 +
  90 + [TestFixture]
  91 + public class when_writing_to_the_stream : has_buffer_pool_fixture
  92 + {
  93 + [Test]
  94 + public void position_is_incremented()
  95 + {
  96 + BufferPoolStream stream = new BufferPoolStream(BufferPool);
  97 + stream.Write(new byte[500], 0, 500);
  98 + Assert.AreEqual(500, stream.Position);
  99 + }
  100 + }
  101 +
  102 + [TestFixture]
  103 + public class when_seeking_in_the_stream : has_buffer_pool_fixture
  104 + {
  105 + [Test]
  106 + public void from_begin_sets_relative_to_beginning()
  107 + {
  108 + BufferPoolStream stream = new BufferPoolStream(BufferPool);
  109 + stream.Write(new byte[500], 0, 500);
  110 + stream.Seek(22, SeekOrigin.Begin);
  111 + Assert.AreEqual(22, stream.Position);
  112 + }
  113 +
  114 + [Test]
  115 + public void from_end_sets_relative_to_end()
  116 + {
  117 + BufferPoolStream stream = new BufferPoolStream(BufferPool);
  118 + stream.Write(new byte[500], 0, 500);
  119 + stream.Seek(-100, SeekOrigin.End);
  120 + Assert.AreEqual(400, stream.Position);
  121 + }
  122 +
  123 + [Test]
  124 + public void from_current_sets_relative_to_current()
  125 + {
  126 + BufferPoolStream stream = new BufferPoolStream(BufferPool);
  127 + stream.Write(new byte[500], 0, 500);
  128 + stream.Seek(-2, SeekOrigin.Current);
  129 + stream.Seek(1, SeekOrigin.Current);
  130 + Assert.AreEqual(499, stream.Position);
  131 + }
  132 +
  133 + [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
  134 + public void a_negative_position_throws_an_argumentexception()
  135 + {
  136 + BufferPoolStream stream = new BufferPoolStream(BufferPool);
  137 + stream.Seek(-1, SeekOrigin.Begin);
  138 + }
  139 +
  140 + [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
  141 + public void seeking_past_end_of_stream_throws_an_argumentexception()
  142 + {
  143 + BufferPoolStream stream = new BufferPoolStream(BufferPool);
  144 + stream.Write(new byte[500], 0, 500);
  145 + stream.Seek(501, SeekOrigin.Begin);
  146 + }
  147 + }
  148 +
  149 +}
555 src/EventStore/EventStore.BufferManagement.Tests/BufferPoolTests.cs
... ... @@ -0,0 +1,555 @@
  1 +// Copyright (c) 2012, Event Store LLP
  2 +// All rights reserved.
  3 +//
  4 +// Redistribution and use in source and binary forms, with or without
  5 +// modification, are permitted provided that the following conditions are
  6 +// met:
  7 +//
  8 +// Redistributions of source code must retain the above copyright notice,
  9 +// this list of conditions and the following disclaimer.
  10 +// Redistributions in binary form must reproduce the above copyright
  11 +// notice, this list of conditions and the following disclaimer in the
  12 +// documentation and/or other materials provided with the distribution.
  13 +// Neither the name of the Event Store LLP nor the names of its
  14 +// contributors may be used to endorse or promote products derived from
  15 +// this software without specific prior written permission
  16 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  20 +// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27 +//
  28 +using System;
  29 +using System.Collections.Generic;
  30 +using NUnit.Framework;
  31 +
  32 +namespace EventStore.BufferManagement.Tests
  33 +{
  34 + public class has_buffer_manager_fixture
  35 + {
  36 + protected BufferManager BufferManager;
  37 +
  38 + [SetUp]
  39 + public virtual void Setup()
  40 + {
  41 + BufferManager = new BufferManager(128, 1024, 1);
  42 + }
  43 + }
  44 +
  45 + [TestFixture]
  46 + public class when_instantiating_a_bufferpool : has_buffer_manager_fixture
  47 + {
  48 + [Test, ExpectedException(typeof(ArgumentException))]
  49 + public void a_negative_initial_buffers_throws_an_argumentexception()
  50 + {
  51 + BufferPool pool = new BufferPool(-1, BufferManager);
  52 + }
  53 +
  54 + [Test, ExpectedException(typeof(ArgumentNullException))]
  55 + public void a_null_buffer_manager_throws_an_argumentnullexception()
  56 + {
  57 + BufferPool pool = new BufferPool(12, null);
  58 + }
  59 +
  60 + [Test]
  61 + public void an_empty_buffer_has_a_length_of_zero()
  62 + {
  63 + BufferPool pool = new BufferPool(1, BufferManager);
  64 + Assert.AreEqual(0, pool.Length);
  65 + }
  66 +
  67 + [Test]
  68 + public void the_requested_buffers_should_be_removed_from_the_buffer_manager()
  69 + {
  70 + int InitialBuffers = BufferManager.AvailableBuffers;
  71 + BufferPool pool = new BufferPool(10, BufferManager);
  72 + Assert.AreEqual(InitialBuffers - 10, BufferManager.AvailableBuffers);
  73 + }
  74 + }
  75 +
  76 + [TestFixture]
  77 + public class when_changing_data_in_a_bufferpool_via_indexer : has_buffer_manager_fixture
  78 + {
  79 + [Test, ExpectedException(typeof(ArgumentException))]
  80 + public void an_index_under_zero_throws_an_argument_exception()
  81 + {
  82 + BufferPool pool = new BufferPool(12, BufferManager);
  83 + pool[-1] = 4;
  84 + }
  85 +
  86 + [Test]
  87 + public void data_that_has_been_set_can_read()
  88 + {
  89 + BufferPool pool = new BufferPool(1, BufferManager);
  90 + pool[3] = 5;
  91 + Assert.AreEqual(5, pool[3]);
  92 + }
  93 +
  94 + [Test]
  95 + public void length_is_updated_when_index_higher_than_count_set()
  96 + {
  97 + BufferPool pool = new BufferPool(1, BufferManager);
  98 + Assert.AreEqual(0, pool.Length);
  99 + pool[3] = 5;
  100 + Assert.AreEqual(4, pool.Length);
  101 + }
  102 +
  103 + [Test]
  104 + public void a_write_will_automatically_grow_the_buffer_pool()
  105 + {
  106 + BufferPool pool = new BufferPool(1, BufferManager);
  107 + int initialCapacity = pool.Capacity;
  108 + pool[initialCapacity + 14] = 5;
  109 + Assert.AreEqual(initialCapacity * 2, pool.Capacity);
  110 + }
  111 +
  112 + [Test]
  113 + public void a_write_past_end_will_check_out_a_buffer_from_the_buffer_pool()
  114 + {
  115 + BufferPool pool = new BufferPool(1, BufferManager);
  116 + int initial = BufferManager.AvailableBuffers;
  117 + pool[pool.Capacity + 14] = 5;
  118 + Assert.AreEqual(initial - 1, BufferManager.AvailableBuffers);
  119 + }
  120 + }
  121 +
  122 + [TestFixture]
  123 + public class when_converting_to_a_byte_array : has_buffer_manager_fixture
  124 + {
  125 + [Test]
  126 + public void the_byte_array_should_be_the_same_length_as_the_pool_with_data()
  127 + {
  128 + BufferPool pool = new BufferPool(5, BufferManager);
  129 + for (int i = 0; i < 500; i++)
  130 + {
  131 + pool[i] = 12;
  132 + }
  133 + Assert.AreEqual(500, pool.ToByteArray().Length);
  134 + }
  135 +
  136 + [Test]
  137 + public void the_byte_array_should_have_the_same_data_as_the_pool_with_multiple_buffers()
  138 + {
  139 + BufferPool pool = new BufferPool(5, BufferManager);
  140 + for (int i = 0; i < 5000; i++)
  141 + {
  142 + pool[i] = (byte)(i % 255);
  143 + }
  144 + byte[] data = pool.ToByteArray();
  145 + for (int i = 0; i < 5000; i++)
  146 + {
  147 + Assert.AreEqual((byte)(i % 255), data[i]);
  148 + }
  149 + }
  150 +
  151 + [Test]
  152 + public void the_byte_array_should_have_the_same_data_as_the_pool_with_a_single_buffer()
  153 + {
  154 + BufferPool pool = new BufferPool(5, BufferManager);
  155 + for (int i = 0; i < 5; i++)
  156 + {
  157 + pool[i] = (byte)(i % 255);
  158 + }
  159 + byte[] data = pool.ToByteArray();
  160 + for (int i = 0; i < 5; i++)
  161 + {
  162 + Assert.AreEqual((byte)(i % 255), data[i]);
  163 + }
  164 + }
  165 +
  166 +
  167 + [Test]
  168 + public void an_empty_pool_should_return_an_empty_array()
  169 + {
  170 + BufferPool pool = new BufferPool(1, BufferManager);
  171 + byte[] arr = pool.ToByteArray();
  172 + Assert.AreEqual(0, arr.Length);
  173 + }
  174 + }
  175 +
  176 + [TestFixture]
  177 + public class when_converting_to_an_effective_IEnumerable_of_arraysegments : has_buffer_manager_fixture
  178 + {
  179 + [Test]
  180 + public void empty_returns_no_results()
  181 + {
  182 + BufferPool pool = new BufferPool(10, BufferManager);
  183 + foreach (ArraySegment<byte> effectiveBuffer in pool.EffectiveBuffers)
  184 + {
  185 + Assert.Fail("should not have been buffers");
  186 + }
  187 + }
  188 +
  189 + [Test]
  190 + public void a_single_partial_segment_can_be_returned()
  191 + {
  192 + BufferPool pool = new BufferPool(1, BufferManager);
  193 + for (byte i = 0; i < 10; i++)
  194 + {
  195 + pool[i] = i;
  196 + }
  197 + List<ArraySegment<byte>> buffers = new List<ArraySegment<byte>>(pool.EffectiveBuffers);
  198 + Assert.IsTrue(buffers.Count == 1);
  199 + for (byte i = 0; i < 10; i++)
  200 + {
  201 + Assert.IsTrue(buffers[0].Array[buffers[0].Offset + i] == i);
  202 + }
  203 + }
  204 +
  205 + [Test]
  206 + public void multiple_segments_can_be_returned()
  207 + {
  208 + BufferManager manager = new BufferManager(3, 1000, 1);
  209 + BufferPool pool = new BufferPool(10, manager);
  210 + for (int i = 0; i < 2500; i++)
  211 + {
  212 + pool[i] = (byte)(i % 255);
  213 + }
  214 + List<ArraySegment<byte>> buffers = new List<ArraySegment<byte>>(pool.EffectiveBuffers);
  215 + Assert.IsTrue(buffers.Count == 3);
  216 + Assert.IsTrue(buffers[0].Count == 1000);
  217 + Assert.IsTrue(buffers[1].Count == 1000);
  218 + Assert.IsTrue(buffers[2].Count == 500);
  219 + }
  220 + }
  221 +
  222 + [TestFixture]
  223 + public class when_reading_data_in_a_bufferpool_via_indexer : has_buffer_manager_fixture
  224 + {
  225 + [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
  226 + public void if_the_index_is_past_the_length_an_argumentoutofrangeexception_is_thrown()
  227 + {
  228 + BufferPool pool = new BufferPool(1, BufferManager);
  229 + byte b = pool[3];
  230 + }
  231 + }
  232 +
  233 +
  234 + [TestFixture]
  235 + public class when_disposing_a_buffer_pool : has_buffer_manager_fixture
  236 + {
  237 + [Test]
  238 + public void buffers_are_released_back_to_the_buffer_pool()
  239 + {
  240 + int initial = BufferManager.AvailableBuffers;
  241 + using (BufferPool pool = new BufferPool(20, BufferManager))
  242 + {
  243 + //sanity check (make sure they are actually gone)
  244 + Assert.AreEqual(initial - 20, BufferManager.AvailableBuffers);
  245 + }
  246 + Assert.AreEqual(initial, BufferManager.AvailableBuffers);
  247 + }
  248 + }
  249 +
  250 + [TestFixture]
  251 + public class when_reading_multiple_bytes : has_buffer_manager_fixture
  252 + {
  253 + [Test, ExpectedException(typeof(ArgumentNullException))]
  254 + public void a_null_read_buffer_throws_an_argumentnullexception()
  255 + {
  256 + BufferPool pool = new BufferPool(1, BufferManager);
  257 + pool.ReadFrom(0, null, 0, 0);
  258 + }
  259 +
  260 + [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
  261 + public void an_offset_larger_than_the_buffer_throws_an_argumentoutofrangeexception()
  262 + {
  263 + BufferPool pool = new BufferPool(1, BufferManager);
  264 + pool.ReadFrom(0, new byte[5], 8, 3);
  265 + }
  266 +
  267 + [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
  268 + public void a_count_larger_than_the_buffer_throws_an_argumentoutofrangeexception()
  269 + {
  270 + BufferPool pool = new BufferPool(1, BufferManager);
  271 + pool.ReadFrom(0, new byte[5], 3, 5);
  272 + }
  273 +
  274 + [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
  275 + public void a_negative_count_throws_an_argumentoutofrangeexception()
  276 + {
  277 + BufferPool pool = new BufferPool(1, BufferManager);
  278 + pool.ReadFrom(0, new byte[5], 3, -1);
  279 + }
  280 +
  281 + [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
  282 + public void a_negative_offset_throws_an_argumentoutofrangeexception()
  283 + {
  284 + BufferPool pool = new BufferPool(1, BufferManager);
  285 + pool.ReadFrom(0, new byte[5], -1, 1);
  286 + }
  287 +
  288 + [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
  289 + public void count_and_offset_together_lerger_than_buffer_throws_an_argumentoutofrangeexception()
  290 + {
  291 + BufferPool pool = new BufferPool(1, BufferManager);
  292 + pool.ReadFrom(0, new byte[5], 4, 2);
  293 + }
  294 +
  295 + [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
  296 + public void a_count_and_offset_together_are_longer_than_pool_length_throws_an_argumentoutofrangeexception()
  297 + {
  298 + BufferPool pool = new BufferPool(1, BufferManager);
  299 + pool[0] = 12;
  300 + pool[1] = 13;
  301 + pool.ReadFrom(3, new byte[5], 0, 5);
  302 + }
  303 +
  304 + [Test]
  305 + public void can_read_within_a_single_buffer_with_no_offset()
  306 + {
  307 + BufferPool pool = new BufferPool(1, BufferManager);
  308 + for (int i = 0; i < 255; i++)
  309 + {
  310 + pool[i] = (byte)i;
  311 + }
  312 +
  313 + byte[] buffer = new byte[255];
  314 + pool.ReadFrom(0, buffer, 0, 255);
  315 + for (int i = 0; i < 255; i++)
  316 + {
  317 + Assert.AreEqual((byte)i, buffer[i]);
  318 + }
  319 + }
  320 +
  321 + [Test]
  322 + public void can_read_from_multiple_buffers()
  323 + {
  324 + BufferPool pool = new BufferPool(1, BufferManager);
  325 + for (int i = 0; i < 5000; i++)
  326 + {
  327 + pool[i] = (byte)(i % 255);
  328 + }
  329 +
  330 + byte[] buffer = new byte[5000];
  331 + pool.ReadFrom(0, buffer, 0, 5000);
  332 + for (int i = 0; i < 5000; i++)
  333 + {
  334 + Assert.AreEqual((byte)(i % 255), buffer[i]);
  335 + }
  336 + }
  337 +
  338 + [Test]
  339 + public void can_read_using_an_offset()
  340 + {
  341 + BufferPool pool = new BufferPool(1, BufferManager);
  342 + for (int i = 5; i < 260; i++)
  343 + {
  344 + pool[i] = (byte)(i - 5);
  345 + }
  346 +
  347 + byte[] buffer = new byte[255];
  348 + pool.ReadFrom(5, buffer, 0, 255);
  349 + for (int i = 0; i < 255; i++)
  350 + {
  351 + Assert.AreEqual((byte)i, buffer[i]);
  352 + }
  353 + }
  354 + }
  355 +
  356 + [TestFixture]
  357 + public class when_writing_multiple_bytes : has_buffer_manager_fixture
  358 + {
  359 + [Test, ExpectedException(typeof(ArgumentNullException))]
  360 + public void a_null_byte_array_throws_an_argumentnullexception()
  361 + {
  362 + BufferPool pool = new BufferPool(1, BufferManager);
  363 + pool.Append(null);
  364 + }
  365 +
  366 + [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
  367 + public void an_offset_larger_than_the_buffer_throws_an_argumentoutofrangeexception()
  368 + {
  369 + BufferPool pool = new BufferPool(1, BufferManager);
  370 + pool.Write(0, new byte[5], 8, 3);
  371 + }
  372 +
  373 + [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
  374 + public void a_count_larger_than_the_buffer_throws_an_argumentoutofrangeexception()
  375 + {
  376 + BufferPool pool = new BufferPool(1, BufferManager);
  377 + pool.Write(0, new byte[5], 3, 5);
  378 + }
  379 +
  380 + [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
  381 + public void a_negative_count_throws_an_argumentoutofrangeexception()
  382 + {
  383 + BufferPool pool = new BufferPool(1, BufferManager);
  384 + pool.Write(0, new byte[5], 3, -1);
  385 + }
  386 +
  387 + [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
  388 + public void a_negative_offset_throws_an_argumentoutofrangeexception()
  389 + {
  390 + BufferPool pool = new BufferPool(1, BufferManager);
  391 + pool.Write(0, new byte[5], -1, 1);
  392 + }
  393 +
  394 + [Test]
  395 + public void length_is_updated_to_include_bytes_written()
  396 + {
  397 + BufferPool pool = new BufferPool(1, BufferManager);
  398 + byte[] data = { 1, 2, 3, 4, 5 };
  399 + pool.Append(data);
  400 + Assert.IsTrue(pool.Length == 5);
  401 + }
  402 +
  403 + [Test]
  404 + public void data_is_written_to_the_internal_buffer()
  405 + {
  406 + BufferPool pool = new BufferPool(1, BufferManager);
  407 + byte[] data = { 1, 2, 3, 4, 5 };
  408 + pool.Append(data);
  409 + for (byte i = 0; i < 5; i++)
  410 + {
  411 + Assert.AreEqual(i + 1, pool[i]);
  412 + }
  413 + }
  414 +
  415 + [Test]
  416 + public void pool_can_expand_capacity()
  417 + {
  418 + BufferPool pool = new BufferPool(1, BufferManager);
  419 + int initialCapacity = pool.Capacity;
  420 + byte[] data = new byte[initialCapacity + 25];
  421 + pool.Append(data);
  422 + Assert.AreEqual(initialCapacity * 2, pool.Capacity);
  423 + }
  424 +
  425 + [Test]
  426 + public void can_write_given_a_self_offset()
  427 + {
  428 + BufferPool pool = new BufferPool(1, BufferManager);
  429 + byte[] data = { 1, 2, 3, 4, 5 };
  430 + pool.Write(4, data, 0, 5); //start at position 4
  431 + for (byte i = 4; i < 9; i++)
  432 + {
  433 + Assert.AreEqual(i - 3, pool[i]);
  434 + }
  435 + }
  436 +
  437 + [Test]
  438 + public void can_write_given_a_source_offset()
  439 + {
  440 + BufferPool pool = new BufferPool(1, BufferManager);
  441 + byte[] data = { 1, 2, 3, 4, 5 };
  442 + pool.Write(0, data, 3, 2);
  443 + Assert.AreEqual(pool[0], 4);
  444 + Assert.AreEqual(pool[1], 5);
  445 + }
  446 + }
  447 +
  448 + [TestFixture]
  449 + public class when_setting_the_length_of_the_pool : has_buffer_manager_fixture
  450 + {
  451 + [Test, ExpectedException(typeof(ArgumentException))]
  452 + public void a_negative_length_throws_an_argumentexception()
  453 + {
  454 + BufferPool pool = new BufferPool(1, BufferManager);
  455 + pool.SetLength(-1, false);
  456 + }
  457 +
  458 + [Test]
  459 + public void a_larger_length_makes_capacity_larger()
  460 + {
  461 + BufferManager manager = new BufferManager(10, 1000, 1);
  462 + BufferPool pool = new BufferPool(1, manager);
  463 + pool.SetLength(5000);
  464 + Assert.AreNotEqual(5000, pool.Capacity);
  465 + }
  466 +
  467 + [Test]
  468 + public void length_is_set_when_setting_length()
  469 + {
  470 + BufferPool pool = new BufferPool(1, BufferManager);
  471 + pool.SetLength(5000, false);
  472 + Assert.AreEqual(5000, pool.Length);
  473 + }
  474 +
  475 + [Test]
  476 + public void a_smaller_length_lowers_capacity()
  477 + {
  478 + BufferManager manager = new BufferManager(10, 1000, 1);
  479 + BufferPool pool = new BufferPool(5, manager);
  480 + pool.SetLength(1);
  481 + Assert.AreEqual(9, manager.AvailableBuffers);
  482 + }
  483 +
  484 + [Test]
  485 + public void a_smaller_length_checks_buffers_back_in_when_allowed()
  486 + {
  487 + BufferManager manager = new BufferManager(10, 1000, 1);
  488 + BufferPool pool = new BufferPool(5, manager);
  489 + pool.SetLength(1, true);
  490 + Assert.AreEqual(9, manager.AvailableBuffers);
  491 + }
  492 +
  493 + [Test]
  494 + public void a_smaller_length_checks_buffers_back_in_when_not_allowed()
  495 + {
  496 + BufferManager manager = new BufferManager(10, 1000, 1);
  497 + BufferPool pool = new BufferPool(5, manager);
  498 + pool.SetLength(1, false);
  499 + Assert.AreEqual(5, manager.AvailableBuffers);
  500 + }
  501 + }
  502 +
  503 + [TestFixture]
  504 + public class when_a_buffer_pool_has_been_disposed : has_buffer_manager_fixture
  505 + {
  506 + private BufferPool m_DisposedPool;
  507 +
  508 + public override void Setup()
  509 + {
  510 + base.Setup();
  511 + m_DisposedPool = new BufferPool(10, BufferManager);
  512 + m_DisposedPool.Dispose();
  513 + }
  514 +
  515 + [Test, ExpectedException(typeof(ObjectDisposedException))]
  516 + public void reading_indexer_throws_objectdisposedexception()
  517 + {
  518 + byte b = m_DisposedPool[0];
  519 + }
  520 +
  521 + [Test, ExpectedException(typeof(ObjectDisposedException))]
  522 + public void writing_indexer_throws_objectdisposedexception()
  523 + {
  524 + m_DisposedPool[0] = 5;
  525 + }
  526 +
  527 + [Test, ExpectedException(typeof(ObjectDisposedException))]
  528 + public void writing_multiple_bytes_throws_objectdisposedexception()
  529 + {
  530 + m_DisposedPool.Append(new byte[] { 1, 2, 3, 4 });
  531 + }
  532 +
  533 +
  534 + [Test, ExpectedException(typeof(ObjectDisposedException))]
  535 + public void effective_enumerator_throws_objectdisposedexception()
  536 + {
  537 + foreach (ArraySegment<byte> segment in m_DisposedPool.EffectiveBuffers)
  538 + {
  539 + }
  540 + }
  541 +
  542 + [Test, ExpectedException(typeof(ObjectDisposedException))]
  543 + public void setting_length_throws_objectdisposedexception()
  544 + {
  545 + m_DisposedPool.SetLength(200);
  546 + }
  547 +
  548 + [Test, ExpectedException(typeof(ObjectDisposedException))]
  549 + public void converting_to_a_byte_array_throws_objectdisposedexception()
  550 + {
  551 + m_DisposedPool.ToByteArray();
  552 + }
  553 +
  554 + }
  555 +}
73 src/EventStore/EventStore.BufferManagement.Tests/EventStore.BufferManagement.Tests.csproj
... ... @@ -0,0 +1,73 @@
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  3 + <PropertyGroup>
  4 + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
  5 + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
  6 + <ProductVersion>8.0.30703</ProductVersion>
  7 + <SchemaVersion>2.0</SchemaVersion>
  8 + <ProjectGuid>{05598608-CF42-49C1-A220-B1B7D1EBD83E}</ProjectGuid>
  9 + <OutputType>Library</OutputType>
  10 + <AppDesignerFolder>Properties</AppDesignerFolder>
  11 + <RootNamespace>EventStore.BufferManagement.Tests</RootNamespace>
  12 + <AssemblyName>EventStore.BufferManagement.Tests</AssemblyName>
  13 + <FileAlignment>512</FileAlignment>
  14 + </PropertyGroup>
  15 + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  16 + <DebugSymbols>true</DebugSymbols>
  17 + <DebugType>full</DebugType>
  18 + <Optimize>false</Optimize>
  19 + <OutputPath>..\..\..\bin\eventstore.tests\debug\anycpu\</OutputPath>
  20 + <DefineConstants>TRACE;DEBUG</DefineConstants>
  21 + <ErrorReport>prompt</ErrorReport>
  22 + <WarningLevel>4</WarningLevel>
  23 + </PropertyGroup>
  24 + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  25 + <DebugType>pdbonly</DebugType>
  26 + <Optimize>true</Optimize>
  27 + <OutputPath>..\..\..\bin\eventstore.tests\release\anycpu\</OutputPath>
  28 + <ErrorReport>prompt</ErrorReport>
  29 + <WarningLevel>4</WarningLevel>
  30 + </PropertyGroup>
  31 + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
  32 + <PlatformTarget>x86</PlatformTarget>
  33 + <OutputPath>..\..\..\bin\eventstore.tests\debug\x86\</OutputPath>
  34 + <DefineConstants>TRACE;DEBUG</DefineConstants>
  35 + <DebugType>none</DebugType>
  36 + <WarningLevel>4</WarningLevel>
  37 + <Optimize>false</Optimize>
  38 + </PropertyGroup>
  39 + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
  40 + <PlatformTarget>x86</PlatformTarget>
  41 + <OutputPath>..\..\..\bin\eventstore.tests\release\x86\</OutputPath>