Search in sources :

Example 1 with MockConnectionFactoryImpl

use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.

the class RawClientTest method testHello.

@Test
public void testHello() throws ConnectionFailedException {
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", -1);
    @Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
    @Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory);
    ClientConnection connection = Mockito.mock(ClientConnection.class);
    connectionFactory.provideConnection(endpoint, connection);
    RawClient rawClient = new RawClient(controller, connectionFactory, new Segment("scope", "testHello", 0));
    rawClient.sendRequest(1, new WireCommands.Hello(0, 0));
    Mockito.verify(connection).send(new WireCommands.Hello(0, 0));
    rawClient.close();
    Mockito.verify(connection).close();
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 2 with MockConnectionFactoryImpl

use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.

the class SegmentOutputStreamTest method testFailDurringFlush.

@Test(timeout = 10000)
public void testFailDurringFlush() throws ConnectionFailedException {
    UUID cid = UUID.randomUUID();
    PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
    MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
    ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
    // Ensure task submitted to executor is run inline.
    implementAsDirectExecutor(executor);
    cf.setExecutor(executor);
    MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf);
    ClientConnection connection = mock(ClientConnection.class);
    cf.provideConnection(uri, connection);
    InOrder order = Mockito.inOrder(connection);
    SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, "");
    output.reconnect();
    order.verify(connection).send(new SetupAppend(1, cid, SEGMENT, ""));
    cf.getProcessor(uri).appendSetup(new AppendSetup(1, SEGMENT, cid, 0));
    ByteBuffer data = getBuffer("test");
    CompletableFuture<Boolean> ack = new CompletableFuture<>();
    output.write(new PendingEvent(null, data, ack));
    order.verify(connection).send(new Append(SEGMENT, cid, 1, Unpooled.wrappedBuffer(data), null));
    assertEquals(false, ack.isDone());
    Mockito.doThrow(new ConnectionFailedException()).when(connection).send(new WireCommands.KeepAlive());
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            cf.getProcessor(uri).appendSetup(new AppendSetup(3, SEGMENT, cid, 1));
            return null;
        }
    }).when(connection).send(new SetupAppend(3, cid, SEGMENT, ""));
    Async.testBlocking(() -> {
        output.flush();
    }, () -> {
        cf.getProcessor(uri).connectionDropped();
    });
    order.verify(connection).send(new SetupAppend(3, cid, SEGMENT, ""));
    assertEquals(true, ack.isDone());
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) InOrder(org.mockito.InOrder) ByteBuffer(java.nio.ByteBuffer) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) CompletableFuture(java.util.concurrent.CompletableFuture) Append(io.pravega.shared.protocol.netty.Append) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) PendingEvent(io.pravega.client.stream.impl.PendingEvent) InvocationOnMock(org.mockito.invocation.InvocationOnMock) 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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Test(org.junit.Test)

Example 3 with MockConnectionFactoryImpl

use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.

the class StreamManagerImplTest method setUp.

@Before
public void setUp() {
    PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
    connectionFactory = new MockConnectionFactoryImpl();
    this.controller = new MockController(uri.getEndpoint(), uri.getPort(), connectionFactory, true);
    this.streamManager = new StreamManagerImpl(controller, connectionFactory);
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) Before(org.junit.Before)

Example 4 with MockConnectionFactoryImpl

use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.

the class BatchClientImplTest method testGetSegmentsWithUnboundedStreamCut.

@Test(timeout = 5000)
public void testGetSegmentsWithUnboundedStreamCut() throws Exception {
    PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
    @Cleanup MockConnectionFactoryImpl connectionFactory = getMockConnectionFactory(location);
    MockController mockController = new MockController(location.getEndpoint(), location.getPort(), connectionFactory, false);
    Stream stream = createStream(SCOPE, STREAM, 3, mockController);
    @Cleanup BatchClientFactoryImpl client = new BatchClientFactoryImpl(mockController, ClientConfig.builder().maxConnectionsPerSegmentStore(1).build(), connectionFactory);
    Iterator<SegmentRange> unBoundedSegments = client.getSegments(stream, StreamCut.UNBOUNDED, StreamCut.UNBOUNDED).getIterator();
    assertTrue(unBoundedSegments.hasNext());
    assertEquals(0L, unBoundedSegments.next().asImpl().getSegment().getSegmentId());
    assertTrue(unBoundedSegments.hasNext());
    assertEquals(1L, unBoundedSegments.next().asImpl().getSegment().getSegmentId());
    assertTrue(unBoundedSegments.hasNext());
    assertEquals(2L, unBoundedSegments.next().asImpl().getSegment().getSegmentId());
    assertFalse(unBoundedSegments.hasNext());
}
Also used : SegmentRange(io.pravega.client.batch.SegmentRange) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) Stream(io.pravega.client.stream.Stream) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 5 with MockConnectionFactoryImpl

use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.

the class BatchClientImplTest method getMockConnectionFactory.

private MockConnectionFactoryImpl getMockConnectionFactory(PravegaNodeUri location) throws ConnectionFailedException {
    MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
    ClientConnection connection = mock(ClientConnection.class);
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            GetStreamSegmentInfo request = (GetStreamSegmentInfo) invocation.getArgument(0);
            connectionFactory.getProcessor(location).process(new StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0));
            return null;
        }
    }).when(connection).send(Mockito.any(GetStreamSegmentInfo.class));
    connectionFactory.provideConnection(location, connection);
    return connectionFactory;
}
Also used : GetStreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.GetStreamSegmentInfo) GetStreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.GetStreamSegmentInfo) StreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.StreamSegmentInfo) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) ClientConnection(io.pravega.client.connection.impl.ClientConnection)

Aggregations

MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)121 MockController (io.pravega.client.stream.mock.MockController)118 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)114 Test (org.junit.Test)114 Cleanup (lombok.Cleanup)86 ClientConnection (io.pravega.client.connection.impl.ClientConnection)73 Segment (io.pravega.client.segment.impl.Segment)41 WireCommands (io.pravega.shared.protocol.netty.WireCommands)37 UUID (java.util.UUID)37 InvocationOnMock (org.mockito.invocation.InvocationOnMock)37 ReplyProcessor (io.pravega.shared.protocol.netty.ReplyProcessor)36 AppendSetup (io.pravega.shared.protocol.netty.WireCommands.AppendSetup)34 SetupAppend (io.pravega.shared.protocol.netty.WireCommands.SetupAppend)34 ByteBuffer (java.nio.ByteBuffer)32 MockSegmentStreamFactory (io.pravega.client.stream.mock.MockSegmentStreamFactory)31 AtomicLong (java.util.concurrent.atomic.AtomicLong)29 CompletableFuture (java.util.concurrent.CompletableFuture)27 InOrder (org.mockito.InOrder)27 SynchronizerClientFactory (io.pravega.client.SynchronizerClientFactory)26 SynchronizerConfig (io.pravega.client.state.SynchronizerConfig)22