use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.
the class ClientConnectionTest method testAppendThrows.
@Test
public void testAppendThrows() throws Exception {
ReplyProcessor processor = new ReplyProcessor();
@Cleanup MockServer server = new MockServer();
server.start();
@Cleanup InlineExecutor executor = new InlineExecutor();
@Cleanup ClientConnection clientConnection = TcpClientConnection.connect(server.getUri(), ClientConfig.builder().build(), processor, executor, null).join();
clientConnection.send(new WireCommands.SetupAppend(1, new UUID(1, 2), "segment", ""));
clientConnection.send(new Append("segment", new UUID(1, 2), 1, new Event(Unpooled.EMPTY_BUFFER), 2));
server.sendReply(new WireCommands.AuthTokenCheckFailed(1, "Injected error"));
AssertExtensions.assertEventuallyEquals(true, () -> processor.failure.get(), 5000);
}
use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.
the class FlowHandlerTest method testCreateConnectionWithSessionDisabled.
@Test
public void testCreateConnectionWithSessionDisabled() throws Exception {
flow = new Flow(0, 10);
ClientConnection connection = flowHandler.createConnectionWithFlowDisabled(processor);
connection.send(new Append("segment0", UUID.randomUUID(), 2, 1, buffer, 10L, flow.asLong()));
assertThrows(IllegalStateException.class, () -> flowHandler.createFlow(flow, processor));
}
use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.
the class SegmentOutputStreamTest method testSealedAfterFlush.
@Test(timeout = 10000)
public void testSealedAfterFlush() throws Exception {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
cf.setExecutor(executorService());
MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf, true);
ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(uri, connection);
InOrder order = Mockito.inOrder(connection);
@SuppressWarnings("resource") SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, true, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, DelegationTokenProviderFactory.createWithEmptyToken());
output.reconnect();
order.verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
cf.getProcessor(uri).appendSetup(new AppendSetup(output.getRequestId(), SEGMENT, cid, 0));
ByteBuffer data = getBuffer("test");
CompletableFuture<Void> ack = new CompletableFuture<>();
output.write(PendingEvent.withoutHeader(null, data, ack));
order.verify(connection).send(new Append(SEGMENT, cid, 1, 1, Unpooled.wrappedBuffer(data), null, output.getRequestId()));
assertEquals(false, ack.isDone());
AssertExtensions.assertBlocks(() -> {
AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush());
}, () -> {
cf.getProcessor(uri).segmentIsSealed(new WireCommands.SegmentIsSealed(output.getRequestId(), SEGMENT, "SomeException", 1));
output.getUnackedEventsOnSeal();
});
AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush());
}
use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.
the class SegmentOutputStreamTest method testCloseDuringTransactionAbort.
@Test(timeout = 10000)
public void testCloseDuringTransactionAbort() throws Exception {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
cf.setExecutor(executorService());
MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf, true);
ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(uri, connection);
InOrder order = Mockito.inOrder(connection);
SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(TXN_SEGMENT, true, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, DelegationTokenProviderFactory.createWithEmptyToken());
output.reconnect();
order.verify(connection).send(new SetupAppend(output.getRequestId(), cid, TXN_SEGMENT, ""));
cf.getProcessor(uri).appendSetup(new AppendSetup(output.getRequestId(), TXN_SEGMENT, cid, 0));
ByteBuffer data = getBuffer("test");
// Write an Event.
CompletableFuture<Void> ack1 = new CompletableFuture<>();
output.write(PendingEvent.withoutHeader(null, data, ack1));
order.verify(connection).send(new Append(TXN_SEGMENT, cid, 1, 1, Unpooled.wrappedBuffer(data), null, output.getRequestId()));
// writer is not complete until a response from Segment Store is received.
assertFalse(ack1.isDone());
// Simulate a NoSuchSegment response from SegmentStore due to a Transaction abort.
cf.getProcessor(uri).noSuchSegment(new WireCommands.NoSuchSegment(output.getRequestId(), TXN_SEGMENT, "SomeException", -1L));
// Trigger a second write.
CompletableFuture<Void> ack2 = new CompletableFuture<>();
output.write(PendingEvent.withoutHeader(null, data, ack2));
// Closing the Segment writer should cause a SegmentSealedException.
AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.close());
}
use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.
the class SegmentOutputStreamTest method testFailDuringFlush.
@Test(timeout = 10000)
public void testFailDuringFlush() throws Exception {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
// Ensure task submitted to executor is run inline.
implementAsDirectExecutor(executor);
cf.setExecutor(executor);
MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf, true);
ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(uri, connection);
InOrder order = Mockito.inOrder(connection);
@Cleanup SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, true, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, DelegationTokenProviderFactory.createWithEmptyToken());
output.reconnect();
order.verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
cf.getProcessor(uri).appendSetup(new AppendSetup(output.getRequestId(), SEGMENT, cid, 0));
ByteBuffer data = getBuffer("test");
CompletableFuture<Void> ack = new CompletableFuture<>();
output.write(PendingEvent.withoutHeader(null, data, ack));
order.verify(connection).send(new Append(SEGMENT, cid, 1, 1, Unpooled.wrappedBuffer(data), null, output.getRequestId()));
assertEquals(false, ack.isDone());
final CountDownLatch connectionDroppedLatch = new CountDownLatch(1);
Mockito.doThrow(new ConnectionFailedException()).when(connection).send(new WireCommands.KeepAlive());
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
// The segment writer will try to reconnect once the connection is failed post sending a KeepAlive.
// enable a response for AppendSetup only after the connection dropped is dropped.
connectionDroppedLatch.await();
cf.getProcessor(uri).appendSetup(new AppendSetup(output.getRequestId(), SEGMENT, cid, 1));
return null;
}
}).when(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
AssertExtensions.assertBlocks(() -> {
output.flush();
}, () -> {
cf.getProcessor(uri).connectionDropped();
connectionDroppedLatch.countDown();
});
order.verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
assertEquals(true, ack.isDone());
}
Aggregations