Search in sources :

Example 26 with InlineExecutor

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);
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InlineExecutor(io.pravega.test.common.InlineExecutor) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.netty.impl.ClientConnection) UUID(java.util.UUID) Cleanup(lombok.Cleanup) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) Test(org.junit.Test)

Example 27 with InlineExecutor

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

Example 28 with InlineExecutor

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

Example 29 with InlineExecutor

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
    }
}
Also used : 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) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) Test(org.junit.Test)

Example 30 with InlineExecutor

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());
}
Also used : MockSegmentIoStreams(io.pravega.client.stream.mock.MockSegmentIoStreams) 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