use of io.pravega.test.common.InlineExecutor in project pravega by pravega.
the class ControllerImplLBTest method testDiscoverySuccessUsingIPAddress.
@Test
public void testDiscoverySuccessUsingIPAddress() throws Exception {
final int serverPort1 = testRPCServer1.getPort();
final int serverPort2 = testRPCServer2.getPort();
// Use 2 servers to discover all the servers.
String localIP = InetAddress.getLoopbackAddress().getHostAddress();
@Cleanup("shutdown") InlineExecutor executor = new InlineExecutor();
final ControllerImpl controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create("pravega://" + localIP + ":" + serverPort1 + "," + localIP + ":" + serverPort2)).build()).retryAttempts(1).build(), executor);
final Set<PravegaNodeUri> uris = fetchFromServers(controllerClient, 3);
// Verify we could reach all 3 controllers.
Assert.assertEquals(3, uris.size());
}
use of io.pravega.test.common.InlineExecutor in project pravega by pravega.
the class ControllerImplLBTest method testDirectSuccessUsingIPAddress.
@Test
public void testDirectSuccessUsingIPAddress() throws Exception {
final int serverPort1 = testRPCServer1.getPort();
final int serverPort2 = testRPCServer2.getPort();
final int serverPort3 = testRPCServer3.getPort();
// Directly use all 3 servers and verify.
String localIP = InetAddress.getLoopbackAddress().getHostAddress();
@Cleanup("shutdown") InlineExecutor executor = new InlineExecutor();
final ControllerImpl controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create("tcp://" + localIP + ":" + serverPort1 + "," + localIP + ":" + serverPort2 + "," + localIP + ":" + serverPort3)).build()).retryAttempts(1).build(), executor);
final Set<PravegaNodeUri> uris = fetchFromServers(controllerClient, 3);
Assert.assertEquals(3, uris.size());
}
use of io.pravega.test.common.InlineExecutor in project pravega by pravega.
the class ControllerImplLBTest method testDiscoverySuccess.
@Test
public void testDiscoverySuccess() throws Exception {
final int serverPort1 = testRPCServer1.getPort();
final int serverPort2 = testRPCServer2.getPort();
// Use 2 servers to discover all the servers.
@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);
final Set<PravegaNodeUri> uris = fetchFromServers(controllerClient, 3);
// Verify we could reach all 3 controllers.
Assert.assertEquals(3, uris.size());
}
use of io.pravega.test.common.InlineExecutor in project pravega by pravega.
the class ControllerImplLBTest method testDirectSuccess.
@Test
public void testDirectSuccess() throws Exception {
final int serverPort1 = testRPCServer1.getPort();
final int serverPort2 = testRPCServer2.getPort();
final int serverPort3 = testRPCServer3.getPort();
// Directly use all 3 servers and verify.
@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);
final Set<PravegaNodeUri> uris = fetchFromServers(controllerClient, 3);
Assert.assertEquals(3, uris.size());
}
use of io.pravega.test.common.InlineExecutor in project pravega by pravega.
the class EventStreamWriterTest method testSegmentSealedInSegmentSealed.
@Test
public void testSegmentSealedInSegmentSealed() {
String scope = "scope";
String streamName = "stream";
String routingKey = "RoutingKey";
StreamImpl stream = new StreamImpl(scope, streamName);
Segment segment1 = new Segment(scope, streamName, 0);
Segment segment2 = new Segment(scope, streamName, 1);
Segment segment3 = new Segment(scope, streamName, 2);
EventWriterConfig config = EventWriterConfig.builder().build();
SegmentOutputStreamFactory streamFactory = Mockito.mock(SegmentOutputStreamFactory.class);
Controller controller = Mockito.mock(Controller.class);
FakeSegmentOutputStream outputStream1 = new FakeSegmentOutputStream(segment1);
FakeSegmentOutputStream outputStream2 = new FakeSegmentOutputStream(segment2);
FakeSegmentOutputStream outputStream3 = new FakeSegmentOutputStream(segment3);
Mockito.when(controller.getCurrentSegments(scope, streamName)).thenReturn(getSegmentsFuture(segment1));
Mockito.when(controller.getSuccessors(segment1)).thenReturn(getReplacement(segment1, segment2));
Mockito.when(controller.getSuccessors(segment2)).thenReturn(getReplacement(segment2, segment3));
Mockito.when(streamFactory.createOutputStreamForSegment(eq(segment1), any(), any(), any())).thenAnswer(i -> {
outputStream1.callBackForSealed = i.getArgument(1);
return outputStream1;
});
Mockito.when(streamFactory.createOutputStreamForSegment(eq(segment2), any(), any(), any())).thenAnswer(i -> {
outputStream2.callBackForSealed = i.getArgument(1);
return outputStream2;
});
Mockito.when(streamFactory.createOutputStreamForSegment(eq(segment3), any(), any(), any())).thenAnswer(i -> {
outputStream3.callBackForSealed = i.getArgument(1);
return outputStream3;
});
JavaSerializer<String> serializer = new JavaSerializer<>();
@Cleanup EventStreamWriter<String> writer = new EventStreamWriterImpl<>(stream, controller, streamFactory, serializer, config, new InlineExecutor());
writer.writeEvent(routingKey, "Foo");
Mockito.verify(controller).getCurrentSegments(any(), any());
assertEquals(1, outputStream1.getUnackedEventsOnSeal().size());
assertTrue(outputStream2.getUnackedEventsOnSeal().isEmpty());
outputStream1.invokeSealedCallBack();
outputStream2.invokeSealedCallBack();
writer.writeEvent(routingKey, "Bar");
Mockito.verify(controller, Mockito.times(1)).getCurrentSegments(any(), any());
assertEquals(1, outputStream2.getUnackedEventsOnSeal().size());
assertEquals("Foo", serializer.deserialize(outputStream2.getUnackedEventsOnSeal().get(0).getData()));
assertEquals(2, outputStream3.getUnackedEventsOnSeal().size());
assertEquals("Foo", serializer.deserialize(outputStream3.getUnackedEventsOnSeal().get(0).getData()));
assertEquals("Bar", serializer.deserialize(outputStream3.getUnackedEventsOnSeal().get(1).getData()));
}
Aggregations