Search in sources :

Example 1 with EmptyTokenProviderImpl

use of io.pravega.client.security.auth.EmptyTokenProviderImpl in project pravega by pravega.

the class SegmentInputStreamFactoryImplTest method testCreateInputStreamForSegmentWithOffset.

@Test
public void testCreateInputStreamForSegmentWithOffset() {
    SegmentInputStreamFactoryImpl factory = new SegmentInputStreamFactoryImpl(controller, cp);
    SegmentInputStream segmentInputStream = factory.createInputStreamForSegment(Segment.fromScopedName("scope/stream/0"), new EmptyTokenProviderImpl(), 100);
    assertEquals(100, segmentInputStream.getOffset());
    assertEquals(Segment.fromScopedName("scope/stream/0"), segmentInputStream.getSegmentId());
}
Also used : EmptyTokenProviderImpl(io.pravega.client.security.auth.EmptyTokenProviderImpl) Test(org.junit.Test)

Example 2 with EmptyTokenProviderImpl

use of io.pravega.client.security.auth.EmptyTokenProviderImpl in project pravega by pravega.

the class LargeEventWriterTest method testBufferSplitting.

@Test(timeout = 5000)
public void testBufferSplitting() throws NoSuchSegmentException, AuthenticationException, SegmentSealedException, ConnectionFailedException {
    Segment segment = Segment.fromScopedName("foo/bar/1");
    MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
    MockController controller = new MockController("localhost", 0, connectionFactory, false);
    ClientConnection connection = Mockito.mock(ClientConnection.class);
    PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
    connectionFactory.provideConnection(location, connection);
    ArrayList<ByteBuf> written = new ArrayList<>();
    answerRequest(connectionFactory, connection, location, CreateTransientSegment.class, r -> new SegmentCreated(r.getRequestId(), "transient-segment"));
    answerRequest(connectionFactory, connection, location, SetupAppend.class, r -> new AppendSetup(r.getRequestId(), segment.getScopedName(), r.getWriterId(), WireCommands.NULL_ATTRIBUTE_VALUE));
    answerRequest(connectionFactory, connection, location, ConditionalBlockEnd.class, r -> {
        ByteBuf data = r.getData();
        written.add(data);
        return new DataAppended(r.getRequestId(), r.getWriterId(), r.getEventNumber(), r.getEventNumber() - 1, r.getExpectedOffset() + data.readableBytes());
    });
    answerRequest(connectionFactory, connection, location, MergeSegments.class, r -> {
        return new SegmentsMerged(r.getRequestId(), r.getSource(), r.getTarget(), -1);
    });
    LargeEventWriter writer = new LargeEventWriter(writerId, controller, connectionFactory);
    EmptyTokenProviderImpl tokenProvider = new EmptyTokenProviderImpl();
    ArrayList<ByteBuffer> buffers = new ArrayList<>();
    buffers.add(ByteBuffer.allocate(Serializer.MAX_EVENT_SIZE * 2 + 1));
    buffers.add(ByteBuffer.allocate(Serializer.MAX_EVENT_SIZE));
    buffers.add(ByteBuffer.allocate(5));
    writer.writeLargeEvent(segment, buffers, tokenProvider, EventWriterConfig.builder().enableLargeEvents(true).build());
    assertEquals(4, written.size());
    assertEquals(Serializer.MAX_EVENT_SIZE, written.get(0).readableBytes());
    assertEquals(Serializer.MAX_EVENT_SIZE, written.get(1).readableBytes());
    assertEquals(Serializer.MAX_EVENT_SIZE, written.get(2).readableBytes());
    assertEquals(6 + WireCommands.TYPE_PLUS_LENGTH_SIZE * 3, written.get(3).readableBytes());
}
Also used : ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) ByteBuffer(java.nio.ByteBuffer) Segment(io.pravega.client.segment.impl.Segment) NoSuchSegment(io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment) CreateTransientSegment(io.pravega.shared.protocol.netty.WireCommands.CreateTransientSegment) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) SegmentCreated(io.pravega.shared.protocol.netty.WireCommands.SegmentCreated) EmptyTokenProviderImpl(io.pravega.client.security.auth.EmptyTokenProviderImpl) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) DataAppended(io.pravega.shared.protocol.netty.WireCommands.DataAppended) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.connection.impl.ClientConnection) SegmentsMerged(io.pravega.shared.protocol.netty.WireCommands.SegmentsMerged) Test(org.junit.Test)

Example 3 with EmptyTokenProviderImpl

use of io.pravega.client.security.auth.EmptyTokenProviderImpl in project pravega by pravega.

the class LargeEventWriterTest method testRetriedErrors.

@Test(timeout = 5000)
public void testRetriedErrors() throws ConnectionFailedException, NoSuchSegmentException, AuthenticationException, SegmentSealedException {
    Segment segment = Segment.fromScopedName("foo/bar/1");
    MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
    MockController controller = new MockController("localhost", 0, connectionFactory, false);
    ClientConnection connection = Mockito.mock(ClientConnection.class);
    PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
    connectionFactory.provideConnection(location, connection);
    EmptyTokenProviderImpl tokenProvider = new EmptyTokenProviderImpl();
    ArrayList<ByteBuffer> events = new ArrayList<>();
    events.add(ByteBuffer.allocate(1));
    AtomicBoolean failed = new AtomicBoolean(false);
    AtomicBoolean succeeded = new AtomicBoolean(false);
    answerRequest(connectionFactory, connection, location, SetupAppend.class, r -> new AppendSetup(r.getRequestId(), segment.getScopedName(), r.getWriterId(), WireCommands.NULL_ATTRIBUTE_VALUE));
    answerRequest(connectionFactory, connection, location, ConditionalBlockEnd.class, r -> {
        ByteBuf data = r.getData();
        return new DataAppended(r.getRequestId(), r.getWriterId(), r.getEventNumber(), r.getEventNumber() - 1, r.getExpectedOffset() + data.readableBytes());
    });
    answerRequest(connectionFactory, connection, location, MergeSegments.class, r -> {
        return new SegmentsMerged(r.getRequestId(), r.getSource(), r.getTarget(), -1);
    });
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            CreateTransientSegment argument = (CreateTransientSegment) invocation.getArgument(0);
            failed.set(true);
            connectionFactory.getProcessor(location).process(new AuthTokenCheckFailed(argument.getRequestId(), "stacktrace", ErrorCode.TOKEN_EXPIRED));
            return null;
        }
    }).doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            CreateTransientSegment argument = (CreateTransientSegment) invocation.getArgument(0);
            succeeded.set(true);
            connectionFactory.getProcessor(location).process(new SegmentCreated(argument.getRequestId(), "transient-segment"));
            return null;
        }
    }).when(connection).send(any(CreateTransientSegment.class));
    LargeEventWriter writer = new LargeEventWriter(writerId, controller, connectionFactory);
    writer.writeLargeEvent(segment, events, tokenProvider, EventWriterConfig.builder().build());
    assertTrue(failed.getAndSet(false));
    assertTrue(succeeded.getAndSet(false));
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            CreateTransientSegment argument = (CreateTransientSegment) invocation.getArgument(0);
            failed.set(true);
            connectionFactory.getProcessor(location).process(new WrongHost(argument.getRequestId(), "foo/bar/1", null, "stacktrace"));
            return null;
        }
    }).doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            CreateTransientSegment argument = (CreateTransientSegment) invocation.getArgument(0);
            succeeded.set(true);
            connectionFactory.getProcessor(location).process(new SegmentCreated(argument.getRequestId(), "transient-segment"));
            return null;
        }
    }).when(connection).send(any(CreateTransientSegment.class));
    writer = new LargeEventWriter(writerId, controller, connectionFactory);
    writer.writeLargeEvent(segment, events, tokenProvider, EventWriterConfig.builder().build());
    assertTrue(failed.getAndSet(false));
    assertTrue(succeeded.getAndSet(false));
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            CreateTransientSegment argument = (CreateTransientSegment) invocation.getArgument(0);
            failed.set(true);
            connectionFactory.getProcessor(location).processingFailure(new ConnectionFailedException());
            return null;
        }
    }).doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            CreateTransientSegment argument = (CreateTransientSegment) invocation.getArgument(0);
            succeeded.set(true);
            connectionFactory.getProcessor(location).process(new SegmentCreated(argument.getRequestId(), "transient-segment"));
            return null;
        }
    }).when(connection).send(any(CreateTransientSegment.class));
    writer = new LargeEventWriter(writerId, controller, connectionFactory);
    writer.writeLargeEvent(segment, events, tokenProvider, EventWriterConfig.builder().build());
    assertTrue(failed.getAndSet(false));
    assertTrue(succeeded.getAndSet(false));
}
Also used : ArrayList(java.util.ArrayList) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) ByteBuf(io.netty.buffer.ByteBuf) Segment(io.pravega.client.segment.impl.Segment) NoSuchSegment(io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment) CreateTransientSegment(io.pravega.shared.protocol.netty.WireCommands.CreateTransientSegment) AuthTokenCheckFailed(io.pravega.shared.protocol.netty.WireCommands.AuthTokenCheckFailed) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) ClientConnection(io.pravega.client.connection.impl.ClientConnection) CreateTransientSegment(io.pravega.shared.protocol.netty.WireCommands.CreateTransientSegment) ByteBuffer(java.nio.ByteBuffer) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) EmptyTokenProviderImpl(io.pravega.client.security.auth.EmptyTokenProviderImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Answer(org.mockito.stubbing.Answer) SegmentCreated(io.pravega.shared.protocol.netty.WireCommands.SegmentCreated) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DataAppended(io.pravega.shared.protocol.netty.WireCommands.DataAppended) MockController(io.pravega.client.stream.mock.MockController) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) SegmentsMerged(io.pravega.shared.protocol.netty.WireCommands.SegmentsMerged) Test(org.junit.Test)

Example 4 with EmptyTokenProviderImpl

use of io.pravega.client.security.auth.EmptyTokenProviderImpl in project pravega by pravega.

the class LargeEventWriterTest method testPipelining.

@Test(timeout = 5000)
public void testPipelining() throws NoSuchSegmentException, AuthenticationException, SegmentSealedException, ConnectionFailedException {
    Segment segment = Segment.fromScopedName("foo/bar/1");
    MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
    MockController controller = new MockController("localhost", 0, connectionFactory, false);
    ClientConnection connection = Mockito.mock(ClientConnection.class);
    PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
    connectionFactory.provideConnection(location, connection);
    ArrayList<ByteBuffer> buffers = new ArrayList<>();
    buffers.add(ByteBuffer.allocate(Serializer.MAX_EVENT_SIZE - WireCommands.TYPE_PLUS_LENGTH_SIZE));
    buffers.add(ByteBuffer.allocate(Serializer.MAX_EVENT_SIZE - WireCommands.TYPE_PLUS_LENGTH_SIZE));
    buffers.add(ByteBuffer.allocate(Serializer.MAX_EVENT_SIZE - WireCommands.TYPE_PLUS_LENGTH_SIZE));
    ArrayList<ConditionalBlockEnd> written = new ArrayList<>();
    answerRequest(connectionFactory, connection, location, CreateTransientSegment.class, r -> new SegmentCreated(r.getRequestId(), "transient-segment"));
    answerRequest(connectionFactory, connection, location, SetupAppend.class, r -> new AppendSetup(r.getRequestId(), segment.getScopedName(), r.getWriterId(), WireCommands.NULL_ATTRIBUTE_VALUE));
    // If appends are not pipelined, the call to writeLargeEvents will stall waiting for the first reply.
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ConditionalBlockEnd argument = (ConditionalBlockEnd) invocation.getArgument(0);
            written.add(argument);
            if (written.size() == buffers.size()) {
                for (ConditionalBlockEnd append : written) {
                    connectionFactory.getProcessor(location).process(new DataAppended(append.getRequestId(), writerId, append.getEventNumber(), append.getEventNumber() - 1, append.getExpectedOffset() + append.getData().readableBytes()));
                }
            }
            return null;
        }
    }).when(connection).send(any(ConditionalBlockEnd.class));
    answerRequest(connectionFactory, connection, location, MergeSegments.class, r -> {
        return new SegmentsMerged(r.getRequestId(), r.getSource(), r.getTarget(), -1);
    });
    LargeEventWriter writer = new LargeEventWriter(writerId, controller, connectionFactory);
    EmptyTokenProviderImpl tokenProvider = new EmptyTokenProviderImpl();
    writer.writeLargeEvent(segment, buffers, tokenProvider, EventWriterConfig.builder().build());
}
Also used : ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) Segment(io.pravega.client.segment.impl.Segment) NoSuchSegment(io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment) CreateTransientSegment(io.pravega.shared.protocol.netty.WireCommands.CreateTransientSegment) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) SegmentCreated(io.pravega.shared.protocol.netty.WireCommands.SegmentCreated) EmptyTokenProviderImpl(io.pravega.client.security.auth.EmptyTokenProviderImpl) ConditionalBlockEnd(io.pravega.shared.protocol.netty.WireCommands.ConditionalBlockEnd) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DataAppended(io.pravega.shared.protocol.netty.WireCommands.DataAppended) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.connection.impl.ClientConnection) SegmentsMerged(io.pravega.shared.protocol.netty.WireCommands.SegmentsMerged) Test(org.junit.Test)

Example 5 with EmptyTokenProviderImpl

use of io.pravega.client.security.auth.EmptyTokenProviderImpl in project pravega by pravega.

the class LargeEventWriterTest method testRetries.

@Test(timeout = 5000)
public void testRetries() throws ConnectionFailedException, NoSuchSegmentException, AuthenticationException {
    Segment segment = Segment.fromScopedName("foo/bar/1");
    MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
    MockController controller = new MockController("localhost", 0, connectionFactory, false);
    ClientConnection connection = Mockito.mock(ClientConnection.class);
    PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
    connectionFactory.provideConnection(location, connection);
    AtomicInteger count = new AtomicInteger(0);
    answerRequest(connectionFactory, connection, location, CreateTransientSegment.class, r -> new SegmentCreated(r.getRequestId(), "transient-segment"));
    answerRequest(connectionFactory, connection, location, SetupAppend.class, r -> new AppendSetup(r.getRequestId(), segment.getScopedName(), r.getWriterId(), WireCommands.NULL_ATTRIBUTE_VALUE));
    answerRequest(connectionFactory, connection, location, ConditionalBlockEnd.class, r -> {
        count.getAndIncrement();
        return new WrongHost(r.getRequestId(), segment.getScopedName(), null, null);
    });
    LargeEventWriter writer = new LargeEventWriter(writerId, controller, connectionFactory);
    EmptyTokenProviderImpl tokenProvider = new EmptyTokenProviderImpl();
    ArrayList<ByteBuffer> buffers = new ArrayList<>();
    buffers.add(ByteBuffer.allocate(5));
    AssertExtensions.assertThrows(RetriesExhaustedException.class, () -> writer.writeLargeEvent(segment, buffers, tokenProvider, EventWriterConfig.builder().initialBackoffMillis(1).backoffMultiple(1).enableLargeEvents(true).retryAttempts(7).build()));
    assertEquals(8, count.get());
}
Also used : ArrayList(java.util.ArrayList) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) ByteBuffer(java.nio.ByteBuffer) Segment(io.pravega.client.segment.impl.Segment) NoSuchSegment(io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment) CreateTransientSegment(io.pravega.shared.protocol.netty.WireCommands.CreateTransientSegment) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) SegmentCreated(io.pravega.shared.protocol.netty.WireCommands.SegmentCreated) EmptyTokenProviderImpl(io.pravega.client.security.auth.EmptyTokenProviderImpl) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.connection.impl.ClientConnection) Test(org.junit.Test)

Aggregations

EmptyTokenProviderImpl (io.pravega.client.security.auth.EmptyTokenProviderImpl)8 Test (org.junit.Test)8 ClientConnection (io.pravega.client.connection.impl.ClientConnection)6 Segment (io.pravega.client.segment.impl.Segment)6 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)6 MockController (io.pravega.client.stream.mock.MockController)6 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)6 CreateTransientSegment (io.pravega.shared.protocol.netty.WireCommands.CreateTransientSegment)6 NoSuchSegment (io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment)6 ByteBuffer (java.nio.ByteBuffer)6 ArrayList (java.util.ArrayList)6 AppendSetup (io.pravega.shared.protocol.netty.WireCommands.AppendSetup)5 SegmentCreated (io.pravega.shared.protocol.netty.WireCommands.SegmentCreated)5 DataAppended (io.pravega.shared.protocol.netty.WireCommands.DataAppended)4 SegmentsMerged (io.pravega.shared.protocol.netty.WireCommands.SegmentsMerged)4 ByteBuf (io.netty.buffer.ByteBuf)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)2 ConditionalBlockEnd (io.pravega.shared.protocol.netty.WireCommands.ConditionalBlockEnd)2 WrongHost (io.pravega.shared.protocol.netty.WireCommands.WrongHost)2