use of io.pravega.test.common.InlineExecutor in project pravega by pravega.
the class SegmentOutputStreamTest method testConnectAndSend.
@Test(timeout = 10000)
public void testConnectAndSend() throws SegmentSealedException, ConnectionFailedException {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
@Cleanup("shutdown") InlineExecutor inlineExecutor = new InlineExecutor();
cf.setExecutor(inlineExecutor);
MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf);
ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(uri, connection);
SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, "");
output.reconnect();
verify(connection).send(new SetupAppend(1, cid, SEGMENT, ""));
cf.getProcessor(uri).appendSetup(new AppendSetup(1, SEGMENT, cid, 0));
sendAndVerifyEvent(cid, connection, output, getBuffer("test"), 1, null);
verifyNoMoreInteractions(connection);
}
use of io.pravega.test.common.InlineExecutor in project pravega by pravega.
the class ControllerImplLBTest method testDiscoveryFailover.
@Test
public void testDiscoveryFailover() throws Exception {
final int serverPort1 = testRPCServer1.getPort();
final int serverPort2 = testRPCServer2.getPort();
// Use 2 servers for discovery. Bring down the first server and ensure discovery happens using the other one.
testRPCServer1.shutdownNow();
testRPCServer1.awaitTermination();
Assert.assertTrue(testRPCServer1.isTerminated());
@Cleanup("shutdown") InlineExecutor executor = new InlineExecutor();
final ControllerImpl controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create("pravega://localhost:" + serverPort1 + ",localhost:" + serverPort2)).build()).retryAttempts(1).build(), executor);
// Verify that we can read from the 2 live servers.
Set<PravegaNodeUri> uris = fetchFromServers(controllerClient, 2);
Assert.assertEquals(2, uris.size());
Assert.assertFalse(uris.contains(new PravegaNodeUri("localhost1", 1)));
// Verify no RPC requests fail due to the failed servers.
Assert.assertTrue(verifyNoFailures(controllerClient));
// Bring down another one and verify.
testRPCServer2.shutdownNow();
testRPCServer2.awaitTermination();
Assert.assertTrue(testRPCServer2.isTerminated());
uris = fetchFromServers(controllerClient, 1);
Assert.assertEquals(1, uris.size());
Assert.assertTrue(uris.contains(new PravegaNodeUri("localhost3", 3)));
// Verify no RPC requests fail due to the failed servers.
Assert.assertTrue(verifyNoFailures(controllerClient));
// Bring down all and verify.
testRPCServer3.shutdownNow();
testRPCServer3.awaitTermination();
Assert.assertTrue(testRPCServer3.isTerminated());
final ControllerImpl client = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create("pravega://localhost:" + serverPort1 + ",localhost:" + serverPort2)).build()).retryAttempts(1).build(), executor);
AssertExtensions.assertThrows(RetriesExhaustedException.class, () -> client.getEndpointForSegment("a/b/0").get());
}
use of io.pravega.test.common.InlineExecutor in project pravega by pravega.
the class ControllerImplLBTest method testDirectFailover.
@Test
public void testDirectFailover() throws Exception {
final int serverPort1 = testRPCServer1.getPort();
final int serverPort2 = testRPCServer2.getPort();
final int serverPort3 = testRPCServer3.getPort();
// Bring down the first server and verify we can fallback to the remaining 2 servers.
testRPCServer1.shutdownNow();
testRPCServer1.awaitTermination();
Assert.assertTrue(testRPCServer1.isTerminated());
@Cleanup("shutdown") InlineExecutor executor = new InlineExecutor();
final ControllerImpl controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create("tcp://localhost:" + serverPort1 + ",localhost:" + serverPort2 + ",localhost:" + serverPort3)).build()).retryAttempts(1).build(), executor);
Set<PravegaNodeUri> uris = fetchFromServers(controllerClient, 2);
Assert.assertEquals(2, uris.size());
Assert.assertFalse(uris.contains(new PravegaNodeUri("localhost1", 1)));
// Verify no RPC requests fail due to the failed servers.
Assert.assertTrue(verifyNoFailures(controllerClient));
// Bring down another one and verify.
testRPCServer2.shutdownNow();
testRPCServer2.awaitTermination();
Assert.assertTrue(testRPCServer2.isTerminated());
uris = fetchFromServers(controllerClient, 1);
Assert.assertEquals(1, uris.size());
Assert.assertTrue(uris.contains(new PravegaNodeUri("localhost3", 3)));
// Verify no RPC requests fail due to the failed servers.
Assert.assertTrue(verifyNoFailures(controllerClient));
// Bring down all and verify.
testRPCServer3.shutdownNow();
testRPCServer3.awaitTermination();
Assert.assertTrue(testRPCServer3.isTerminated());
AssertExtensions.assertThrows(RetriesExhaustedException.class, () -> controllerClient.getEndpointForSegment("a/b/0").get());
}
use of io.pravega.test.common.InlineExecutor in project pravega by pravega.
the class EventStreamWriterTest method testFailOnClose.
@Test
public void testFailOnClose() throws SegmentSealedException {
String scope = "scope";
String streamName = "stream";
StreamImpl stream = new StreamImpl(scope, streamName);
Segment segment = new Segment(scope, streamName, 0);
EventWriterConfig config = EventWriterConfig.builder().build();
SegmentOutputStreamFactory streamFactory = Mockito.mock(SegmentOutputStreamFactory.class);
Controller controller = Mockito.mock(Controller.class);
Mockito.when(controller.getCurrentSegments(scope, streamName)).thenReturn(getSegmentsFuture(segment));
SegmentOutputStream outputStream = Mockito.mock(SegmentOutputStream.class);
Mockito.when(streamFactory.createOutputStreamForSegment(eq(segment), any(), any(), any())).thenReturn(outputStream);
EventStreamWriter<String> writer = new EventStreamWriterImpl<>(stream, controller, streamFactory, new JavaSerializer<>(), config, new InlineExecutor());
Mockito.doThrow(new RuntimeException("Intentional exception")).when(outputStream).close();
writer.writeEvent("Foo");
writer.writeEvent("Bar");
try {
writer.close();
fail();
} catch (RuntimeException e) {
// expected.
}
try {
writer.writeEvent("fail");
fail();
} catch (IllegalStateException e) {
// expected
}
}
use of io.pravega.test.common.InlineExecutor in project pravega by pravega.
the class EventStreamWriterTest method testSegmentSealedInFlush.
@Test
public void testSegmentSealedInFlush() throws EndOfSegmentException, SegmentTruncatedException {
String scope = "scope";
String streamName = "stream";
StreamImpl stream = new StreamImpl(scope, streamName);
Segment segment1 = new Segment(scope, streamName, 0);
Segment segment2 = new Segment(scope, streamName, 1);
EventWriterConfig config = EventWriterConfig.builder().build();
SegmentOutputStreamFactory streamFactory = Mockito.mock(SegmentOutputStreamFactory.class);
Controller controller = Mockito.mock(Controller.class);
FakeSegmentOutputStream outputStream = new FakeSegmentOutputStream(segment1);
Mockito.when(controller.getCurrentSegments(scope, streamName)).thenReturn(getSegmentsFuture(segment1));
Mockito.when(controller.getSuccessors(segment1)).thenReturn(getReplacement(segment1, segment2));
Mockito.when(streamFactory.createOutputStreamForSegment(eq(segment1), any(), any(), any())).thenAnswer(i -> {
outputStream.callBackForSealed = i.getArgument(1);
return outputStream;
});
JavaSerializer<String> serializer = new JavaSerializer<>();
@Cleanup EventStreamWriter<String> writer = new EventStreamWriterImpl<>(stream, controller, streamFactory, serializer, config, new InlineExecutor());
writer.writeEvent("Foo");
Mockito.verify(controller).getCurrentSegments(any(), any());
assertTrue(outputStream.getUnackedEventsOnSeal().size() > 0);
MockSegmentIoStreams outputStream2 = new MockSegmentIoStreams(segment2);
Mockito.when(streamFactory.createOutputStreamForSegment(eq(segment2), any(), any(), any())).thenReturn(outputStream2);
outputStream.invokeSealedCallBack();
writer.flush();
Mockito.verify(controller, Mockito.times(1)).getCurrentSegments(any(), any());
assertTrue(outputStream2.fetchCurrentSegmentLength() > 0);
assertEquals(serializer.serialize("Foo"), outputStream2.read());
}
Aggregations