@Override public void flush() throws IOException { out.flush(); }
private boolean flushInternal() { boolean success = true; for (SegmentOutputStream writer : selector.getWriters()) { try { writer.flush(); } catch (SegmentSealedException e) { // Segment sealed exception observed during a flush. Re-run flush on all the // available writers. success = false; log.warn("Flush on segment {} failed due to {}, it will be retried.", writer.getSegmentName(), e.getMessage()); } } return success; }
@Override public void writeUnconditionally(T value) { CompletableFuture<Void> ack = new CompletableFuture<>(); ByteBuffer serialized = serializer.serialize(value); try { PendingEvent event = PendingEvent.withHeader(null, serialized, ack); log.trace("Unconditionally writing: {}", value); synchronized (lock) { out.write(event); out.flush(); } } catch (SegmentSealedException e) { throw new CorruptedStateException("Unexpected end of segment ", e); } Futures.getAndHandleExceptions(ack, RuntimeException::new); }
@Override public void flush() throws TxnFailedException { checkFailed(); try { out.flush(); synchronized (lock) { removeCompleted(); checkFailed(); } } catch (SegmentSealedException e) { throw new TxnFailedException(e); } }
@Test(timeout = 5000) public void testFlush() throws TxnFailedException, SegmentSealedException { UUID uuid = UUID.randomUUID(); SegmentOutputStream outputStream = Mockito.mock(SegmentOutputStream.class); @Cleanup SegmentTransactionImpl<String> txn = new SegmentTransactionImpl<>(uuid, outputStream, new JavaSerializer<String>()); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { PendingEvent event = (PendingEvent) invocation.getArgument(0); event.getAckFuture().complete(null); return null; } }).when(outputStream).write(Mockito.any(PendingEvent.class)); txn.writeEvent("hi"); verify(outputStream).write(Mockito.any(PendingEvent.class)); txn.flush(); verify(outputStream).flush(); Mockito.verifyNoMoreInteractions(outputStream); }
SegmentOutputStream out = segmentproducerClient.createOutputStreamForSegment(segment, segmentSealedCallback, EventWriterConfig.builder().build(), ""); out.write(PendingEvent.withHeader(null, ByteBuffer.wrap(testString.getBytes()), new CompletableFuture<>())); out.flush();