Search in sources :

Example 1 with MockController

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

the class StreamManagerImplTest method setUp.

@Before
public void setUp() {
    PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
    MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
    this.controller = new MockController(uri.getEndpoint(), uri.getPort(), cf);
    this.streamManager = new StreamManagerImpl(controller);
}
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 2 with MockController

use of io.pravega.client.stream.mock.MockController 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 3 with MockController

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

the class SegmentMetadataClientTest method testCurrentStreamLength.

@Test(timeout = 10000)
public void testCurrentStreamLength() throws Exception {
    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);
    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 StreamSegmentInfo(1, segment.getScopedName(), true, false, false, 0, 123, 121));
            return null;
        }
    }).when(connection).send(new WireCommands.GetStreamSegmentInfo(1, segment.getScopedName(), ""));
    long length = client.fetchCurrentSegmentLength();
    assertEquals(123, length);
}
Also used : StreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.StreamSegmentInfo) 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 4 with MockController

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

the class SegmentMetadataClientTest method compareAndSetAttribute.

@Test(timeout = 10000)
public void compareAndSetAttribute() throws Exception {
    UUID attributeId = SegmentAttribute.RevisionStreamClientMark.getValue();
    Segment segment = new Segment("scope", "testRetry", 4);
    PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0);
    MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
    MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), cf);
    ClientConnection connection = mock(ClientConnection.class);
    cf.provideConnection(endpoint, connection);
    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 SegmentAttributeUpdated(1, true));
            return null;
        }
    }).when(connection).send(new WireCommands.UpdateSegmentAttribute(1, segment.getScopedName(), attributeId, 1234, -1234, ""));
    assertTrue(client.compareAndSetAttribute(SegmentAttribute.RevisionStreamClientMark, -1234, 1234));
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) SegmentAttributeUpdated(io.pravega.shared.protocol.netty.WireCommands.SegmentAttributeUpdated) 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 5 with MockController

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

the class SegmentOutputStreamTest method testFlush.

@Test(timeout = 10000)
public void testFlush() throws ConnectionFailedException, SegmentSealedException {
    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> acked1 = new CompletableFuture<>();
    output.write(new PendingEvent(null, data, acked1));
    order.verify(connection).send(new Append(SEGMENT, cid, 1, Unpooled.wrappedBuffer(data), null));
    assertEquals(false, acked1.isDone());
    Async.testBlocking(() -> output.flush(), () -> cf.getProcessor(uri).dataAppended(new WireCommands.DataAppended(cid, 1, 0)));
    assertEquals(false, acked1.isCompletedExceptionally());
    assertEquals(true, acked1.isDone());
    order.verify(connection).send(new WireCommands.KeepAlive());
    CompletableFuture<Boolean> acked2 = new CompletableFuture<>();
    output.write(new PendingEvent(null, data, acked2));
    order.verify(connection).send(new Append(SEGMENT, cid, 2, Unpooled.wrappedBuffer(data), null));
    assertEquals(false, acked2.isDone());
    Async.testBlocking(() -> output.flush(), () -> cf.getProcessor(uri).dataAppended(new WireCommands.DataAppended(cid, 2, 1)));
    assertEquals(false, acked2.isCompletedExceptionally());
    assertEquals(true, acked2.isDone());
    order.verify(connection).send(new WireCommands.KeepAlive());
    order.verifyNoMoreInteractions();
}
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) 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) Test(org.junit.Test)

Aggregations

MockController (io.pravega.client.stream.mock.MockController)50 Test (org.junit.Test)49 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)48 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)47 Cleanup (lombok.Cleanup)38 ClientConnection (io.pravega.client.netty.impl.ClientConnection)30 UUID (java.util.UUID)22 WireCommands (io.pravega.shared.protocol.netty.WireCommands)20 SetupAppend (io.pravega.shared.protocol.netty.WireCommands.SetupAppend)19 CompletableFuture (java.util.concurrent.CompletableFuture)17 PendingEvent (io.pravega.client.stream.impl.PendingEvent)16 AppendSetup (io.pravega.shared.protocol.netty.WireCommands.AppendSetup)16 ClientFactory (io.pravega.client.ClientFactory)15 Segment (io.pravega.client.segment.impl.Segment)15 SynchronizerConfig (io.pravega.client.state.SynchronizerConfig)15 MockSegmentStreamFactory (io.pravega.client.stream.mock.MockSegmentStreamFactory)15 InOrder (org.mockito.InOrder)14 InvocationOnMock (org.mockito.invocation.InvocationOnMock)13 Append (io.pravega.shared.protocol.netty.Append)12 ByteBuffer (java.nio.ByteBuffer)12