Search in sources :

Example 6 with InlineExecutor

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());
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InlineExecutor(io.pravega.test.common.InlineExecutor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 7 with InlineExecutor

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());
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InlineExecutor(io.pravega.test.common.InlineExecutor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 8 with InlineExecutor

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());
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InlineExecutor(io.pravega.test.common.InlineExecutor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 9 with InlineExecutor

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());
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InlineExecutor(io.pravega.test.common.InlineExecutor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 10 with InlineExecutor

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()));
}
Also used : Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) SegmentOutputStreamFactory(io.pravega.client.segment.impl.SegmentOutputStreamFactory) InlineExecutor(io.pravega.test.common.InlineExecutor) Test(org.junit.Test)

Aggregations

InlineExecutor (io.pravega.test.common.InlineExecutor)33 Test (org.junit.Test)33 Cleanup (lombok.Cleanup)30 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)16 Segment (io.pravega.client.segment.impl.Segment)12 SegmentOutputStreamFactory (io.pravega.client.segment.impl.SegmentOutputStreamFactory)12 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)12 UUID (java.util.UUID)11 ClientConnection (io.pravega.client.netty.impl.ClientConnection)10 MockController (io.pravega.client.stream.mock.MockController)10 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)9 AppendSetup (io.pravega.shared.protocol.netty.WireCommands.AppendSetup)9 SetupAppend (io.pravega.shared.protocol.netty.WireCommands.SetupAppend)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 PendingEvent (io.pravega.client.stream.impl.PendingEvent)7 Append (io.pravega.shared.protocol.netty.Append)6 ByteBuffer (java.nio.ByteBuffer)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 InOrder (org.mockito.InOrder)6 MockSegmentIoStreams (io.pravega.client.stream.mock.MockSegmentIoStreams)5