@@ -177,72 +177,6 @@ public void sendBatchAsync(Batch sentBatch, DispatchLogHandler handler) {
177177 }
178178 }
179179
180- @ Test
181- public void testBatchAccumulationStopsWhenMemoryLimitIsReached () throws Exception {
182- final Peer localPeer = createPeer (1 , 6697 );
183- final Peer remotePeer = createPeer (2 , 6698 );
184- final IoTConsensusConfig config =
185- IoTConsensusConfig .newBuilder ()
186- .setReplication (
187- IoTConsensusConfig .Replication .newBuilder ()
188- .setMaxLogEntriesNumPerBatch (1024 )
189- .setMaxSizePerBatch (1 )
190- .setMaxWaitingTimeForAccumulatingBatchInMs (10_000 )
191- .build ())
192- .build ();
193- final ScheduledExecutorService backgroundTaskService =
194- Executors .newSingleThreadScheduledExecutor ();
195- final ExecutorService executorService = Executors .newSingleThreadExecutor ();
196- LogDispatcher .LogDispatcherThread dispatcherThread = null ;
197- Future <?> dispatcherFuture = null ;
198- try {
199- final IoTConsensusServerImpl server =
200- createServer (
201- localPeer , Collections .singletonList (localPeer ), config , backgroundTaskService );
202- final CountDownLatch batchSent = new CountDownLatch (1 );
203- final AtomicInteger getBatchInvocations = new AtomicInteger ();
204- dispatcherThread =
205- server .getLogDispatcher ().new LogDispatcherThread (remotePeer , config , 0 ) {
206- @ Override
207- public Batch getBatch () {
208- return getBatchInvocations .getAndIncrement () == 0
209- ? new Batch (config )
210- : createBatch (config , 1 );
211- }
212-
213- @ Override
214- public void sendBatchAsync (Batch sentBatch , DispatchLogHandler handler ) {
215- assertEquals (1 , getPendingEntriesSize ());
216- assertEquals (1 , getBufferRequestSize ());
217- batchSent .countDown ();
218- Thread .currentThread ().interrupt ();
219- }
220- };
221- final IndexedConsensusRequest firstRequest =
222- new IndexedConsensusRequest (1 , Collections .singletonList (new TestEntry (1 , localPeer )));
223- firstRequest .buildSerializedRequests ();
224- final IndexedConsensusRequest secondRequest =
225- new IndexedConsensusRequest (2 , Collections .singletonList (new TestEntry (2 , localPeer )));
226- secondRequest .buildSerializedRequests ();
227- assertTrue (dispatcherThread .offer (firstRequest ));
228- assertTrue (dispatcherThread .offer (secondRequest ));
229-
230- dispatcherFuture = executorService .submit (dispatcherThread );
231- assertTrue (batchSent .await (2 , TimeUnit .SECONDS ));
232- dispatcherFuture .get (2 , TimeUnit .SECONDS );
233- } finally {
234- if (dispatcherFuture != null ) {
235- dispatcherFuture .cancel (true );
236- }
237- executorService .shutdownNow ();
238- executorService .awaitTermination (5 , TimeUnit .SECONDS );
239- if (dispatcherThread != null ) {
240- dispatcherThread .stop ();
241- }
242- backgroundTaskService .shutdownNow ();
243- }
244- }
245-
246180 @ Test
247181 public void testReloadConfigUpdatesExistingDispatcherPipeline () throws Exception {
248182 final Peer localPeer = createPeer (1 , 6677 );
0 commit comments