Search in sources :

Example 36 with PravegaNodeUri

use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.

the class AsyncSegmentInputStreamTest method testWrongOffsetReturned.

@Test(timeout = 10000)
public void testWrongOffsetReturned() throws ConnectionFailedException {
    Segment segment = new Segment("scope", "testWrongOffsetReturned", 0);
    byte[] good = new byte[] { 0, 1, 2, 3, 4 };
    byte[] bad = new byte[] { 9, 8, 7, 6 };
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
    MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
    MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory);
    @Cleanup AsyncSegmentInputStreamImpl in = new AsyncSegmentInputStreamImpl(controller, connectionFactory, segment, "");
    ClientConnection c = mock(ClientConnection.class);
    connectionFactory.provideConnection(endpoint, c);
    CompletableFuture<SegmentRead> readFuture = in.read(1234, 5678);
    Async.testBlocking(() -> readFuture.get(), () -> {
        ReplyProcessor processor = connectionFactory.getProcessor(endpoint);
        processor.segmentRead(new WireCommands.SegmentRead(segment.getScopedName(), 1235, false, false, ByteBuffer.wrap(bad)));
        processor.segmentRead(new WireCommands.SegmentRead(segment.getScopedName(), 1234, false, false, ByteBuffer.wrap(good)));
    });
    verify(c).sendAsync(new WireCommands.ReadSegment(segment.getScopedName(), 1234, 5678, ""));
    assertTrue(Futures.isSuccessful(readFuture));
    assertEquals(ByteBuffer.wrap(good), readFuture.join().getData());
    verifyNoMoreInteractions(c);
}
Also used : Cleanup(lombok.Cleanup) SegmentRead(io.pravega.shared.protocol.netty.WireCommands.SegmentRead) ReadSegment(io.pravega.shared.protocol.netty.WireCommands.ReadSegment) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) SegmentRead(io.pravega.shared.protocol.netty.WireCommands.SegmentRead) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) ReadSegment(io.pravega.shared.protocol.netty.WireCommands.ReadSegment) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.netty.impl.ClientConnection) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ReplyProcessor(io.pravega.shared.protocol.netty.ReplyProcessor) Test(org.junit.Test)

Example 37 with PravegaNodeUri

use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.

the class SegmentMetadataClientTest method testTruncate.

@Test(timeout = 10000)
public void testTruncate() throws Exception {
    Segment segment = new Segment("scope", "testTruncate", 4);
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0);
    @Cleanup MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
    @Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), cf);
    @Cleanup ClientConnection connection = mock(ClientConnection.class);
    cf.provideConnection(endpoint, connection);
    @Cleanup SegmentMetadataClientImpl client = new SegmentMetadataClientImpl(segment, controller, cf, "");
    client.getConnection();
    ReplyProcessor processor = cf.getProcessor(endpoint);
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            processor.process(new SegmentTruncated(1, segment.getScopedName()));
            return null;
        }
    }).when(connection).send(new WireCommands.TruncateSegment(1, segment.getScopedName(), 123L, ""));
    client.truncateSegment(segment, 123L);
    Mockito.verify(connection).send(new WireCommands.TruncateSegment(1, segment.getScopedName(), 123L, ""));
}
Also used : SegmentTruncated(io.pravega.shared.protocol.netty.WireCommands.SegmentTruncated) Cleanup(lombok.Cleanup) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.netty.impl.ClientConnection) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ReplyProcessor(io.pravega.shared.protocol.netty.ReplyProcessor) Test(org.junit.Test)

Example 38 with PravegaNodeUri

use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.

the class SegmentMetadataClientTest method testReconnects.

@Test(timeout = 10000)
public void testReconnects() throws Exception {
    Segment segment = new Segment("scope", "testRetry", 4);
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0);
    @Cleanup MockConnectionFactoryImpl cf = Mockito.spy(new MockConnectionFactoryImpl());
    @Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), cf);
    @Cleanup ClientConnection connection = mock(ClientConnection.class);
    cf.provideConnection(endpoint, connection);
    @Cleanup SegmentMetadataClientImpl client = new SegmentMetadataClientImpl(segment, controller, cf, "");
    client.getConnection();
    WireCommands.GetStreamSegmentInfo getSegmentInfo1 = new WireCommands.GetStreamSegmentInfo(1, segment.getScopedName(), "");
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ReplyProcessor processor = cf.getProcessor(endpoint);
            processor.connectionDropped();
            return null;
        }
    }).when(connection).send(getSegmentInfo1);
    WireCommands.GetStreamSegmentInfo getSegmentInfo2 = new WireCommands.GetStreamSegmentInfo(2, segment.getScopedName(), "");
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ReplyProcessor processor = cf.getProcessor(endpoint);
            processor.process(new StreamSegmentInfo(2, segment.getScopedName(), true, false, false, 0, 123, 121));
            return null;
        }
    }).when(connection).send(getSegmentInfo2);
    long length = client.fetchCurrentSegmentLength();
    InOrder order = Mockito.inOrder(connection, cf);
    order.verify(cf).establishConnection(eq(endpoint), any(ReplyProcessor.class));
    order.verify(connection).send(getSegmentInfo1);
    order.verify(cf).establishConnection(eq(endpoint), any(ReplyProcessor.class));
    order.verify(connection).send(getSegmentInfo2);
    order.verify(cf).getProcessor(eq(endpoint));
    order.verifyNoMoreInteractions();
    assertEquals(123, length);
}
Also used : StreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.StreamSegmentInfo) InOrder(org.mockito.InOrder) Cleanup(lombok.Cleanup) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.netty.impl.ClientConnection) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ReplyProcessor(io.pravega.shared.protocol.netty.ReplyProcessor) Test(org.junit.Test)

Example 39 with PravegaNodeUri

use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.

the class SegmentMetadataClientTest method testGetProperty.

@Test(timeout = 10000)
public void testGetProperty() throws Exception {
    UUID attributeId = SegmentAttribute.RevisionStreamClientMark.getValue();
    Segment segment = new Segment("scope", "testRetry", 4);
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0);
    @Cleanup MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
    @Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), cf);
    @Cleanup ClientConnection connection = mock(ClientConnection.class);
    cf.provideConnection(endpoint, connection);
    @Cleanup SegmentMetadataClientImpl client = new SegmentMetadataClientImpl(segment, controller, cf, "");
    client.getConnection();
    ReplyProcessor processor = cf.getProcessor(endpoint);
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            processor.process(new WireCommands.SegmentAttribute(1, 123));
            return null;
        }
    }).when(connection).send(new WireCommands.GetSegmentAttribute(1, segment.getScopedName(), attributeId, ""));
    long value = client.fetchProperty(SegmentAttribute.RevisionStreamClientMark);
    assertEquals(123, value);
}
Also used : Cleanup(lombok.Cleanup) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.netty.impl.ClientConnection) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ReplyProcessor(io.pravega.shared.protocol.netty.ReplyProcessor) Test(org.junit.Test)

Example 40 with PravegaNodeUri

use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.

the class SegmentMetadataClientTest method testExceptionOnSend.

@Test(timeout = 10000)
public void testExceptionOnSend() throws Exception {
    Segment segment = new Segment("scope", "testRetry", 4);
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0);
    @Cleanup("shutdown") InlineExecutor executor = new InlineExecutor();
    @Cleanup ConnectionFactory cf = Mockito.mock(ConnectionFactory.class);
    Mockito.when(cf.getInternalExecutor()).thenReturn(executor);
    @Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), cf);
    ClientConnection connection1 = mock(ClientConnection.class);
    ClientConnection connection2 = mock(ClientConnection.class);
    AtomicReference<ReplyProcessor> processor = new AtomicReference<>();
    Mockito.when(cf.establishConnection(Mockito.eq(endpoint), Mockito.any())).thenReturn(Futures.failedFuture(new ConnectionFailedException())).thenReturn(CompletableFuture.completedFuture(connection1)).thenAnswer(new Answer<CompletableFuture<ClientConnection>>() {

        @Override
        public CompletableFuture<ClientConnection> answer(InvocationOnMock invocation) throws Throwable {
            processor.set(invocation.getArgument(1));
            return CompletableFuture.completedFuture(connection2);
        }
    });
    WireCommands.GetStreamSegmentInfo getSegmentInfo1 = new WireCommands.GetStreamSegmentInfo(2, segment.getScopedName(), "");
    Mockito.doThrow(new ConnectionFailedException()).when(connection1).send(getSegmentInfo1);
    WireCommands.GetStreamSegmentInfo getSegmentInfo2 = new WireCommands.GetStreamSegmentInfo(3, segment.getScopedName(), "");
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            processor.get().process(new StreamSegmentInfo(3, segment.getScopedName(), true, false, false, 0, 123, 121));
            return null;
        }
    }).when(connection2).send(getSegmentInfo2);
    @Cleanup SegmentMetadataClientImpl client = new SegmentMetadataClientImpl(segment, controller, cf, "");
    InOrder order = Mockito.inOrder(connection1, connection2, cf);
    long length = client.fetchCurrentSegmentLength();
    order.verify(cf, Mockito.times(2)).establishConnection(Mockito.eq(endpoint), Mockito.any());
    order.verify(connection1).send(getSegmentInfo1);
    order.verify(connection1).close();
    order.verify(cf).establishConnection(Mockito.eq(endpoint), Mockito.any());
    order.verify(connection2).send(getSegmentInfo2);
    order.verifyNoMoreInteractions();
    assertEquals(123, length);
}
Also used : StreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.StreamSegmentInfo) Cleanup(lombok.Cleanup) ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) CompletableFuture(java.util.concurrent.CompletableFuture) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InlineExecutor(io.pravega.test.common.InlineExecutor) ClientConnection(io.pravega.client.netty.impl.ClientConnection) WireCommands(io.pravega.shared.protocol.netty.WireCommands) InOrder(org.mockito.InOrder) AtomicReference(java.util.concurrent.atomic.AtomicReference) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockController(io.pravega.client.stream.mock.MockController) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) ReplyProcessor(io.pravega.shared.protocol.netty.ReplyProcessor) Test(org.junit.Test)

Aggregations

PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)61 Test (org.junit.Test)54 MockController (io.pravega.client.stream.mock.MockController)48 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)47 Cleanup (lombok.Cleanup)42 ClientConnection (io.pravega.client.netty.impl.ClientConnection)33 UUID (java.util.UUID)24 WireCommands (io.pravega.shared.protocol.netty.WireCommands)22 SetupAppend (io.pravega.shared.protocol.netty.WireCommands.SetupAppend)20 Segment (io.pravega.client.segment.impl.Segment)17 AppendSetup (io.pravega.shared.protocol.netty.WireCommands.AppendSetup)17 InlineExecutor (io.pravega.test.common.InlineExecutor)17 CompletableFuture (java.util.concurrent.CompletableFuture)17 ClientFactory (io.pravega.client.ClientFactory)15 SynchronizerConfig (io.pravega.client.state.SynchronizerConfig)15 PendingEvent (io.pravega.client.stream.impl.PendingEvent)15 MockSegmentStreamFactory (io.pravega.client.stream.mock.MockSegmentStreamFactory)15 InOrder (org.mockito.InOrder)14 Append (io.pravega.shared.protocol.netty.Append)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13