use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class SegmentMetadataClientTest method testTokenCheckFailed.
@Test(timeout = 10000)
public void testTokenCheckFailed() throws ConnectionFailedException {
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, true);
@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 {
WireCommands.GetStreamSegmentInfo getStreamInfo = invocation.getArgument(0);
processor.process(new WireCommands.AuthTokenCheckFailed(getStreamInfo.getRequestId(), "server-stacktrace", WireCommands.AuthTokenCheckFailed.ErrorCode.TOKEN_CHECK_FAILED));
return null;
}
}).when(connection).send(any(WireCommands.GetStreamSegmentInfo.class));
AssertExtensions.assertThrows("TokenException was not thrown or server stacktrace contained unexpected content.", () -> client.fetchCurrentSegmentLength().join(), e -> e instanceof InvalidTokenException && e.getMessage().contains("serverStackTrace=server-stacktrace"));
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class SegmentMetadataClientTest method compareAndSetAttribute.
@Test(timeout = 10000)
public void compareAndSetAttribute() throws ConnectionFailedException {
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, true);
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 {
WireCommands.UpdateSegmentAttribute request = invocation.getArgument(0);
processor.process(new SegmentAttributeUpdated(request.getRequestId(), true));
return null;
}
}).when(connection).send(any(WireCommands.UpdateSegmentAttribute.class));
assertTrue(client.compareAndSetAttribute(SegmentAttribute.RevisionStreamClientMark, -1234, 1234).join());
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class SegmentMetadataClientTest method testTokenExpiry.
@Test(timeout = 10000)
public void testTokenExpiry() throws ConnectionFailedException {
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, true);
@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 {
WireCommands.GetStreamSegmentInfo getStreamInfo = invocation.getArgument(0);
processor.process(new WireCommands.AuthTokenCheckFailed(getStreamInfo.getRequestId(), "server-stacktrace", WireCommands.AuthTokenCheckFailed.ErrorCode.TOKEN_EXPIRED));
return null;
}
}).when(connection).send(any(WireCommands.GetStreamSegmentInfo.class));
AssertExtensions.assertThrows("ConnectionFailedException was not thrown or server stacktrace contained unexpected content.", () -> client.getStreamSegmentInfo().join(), e -> e instanceof ConnectionFailedException && e.getMessage().contains("serverStackTrace=server-stacktrace"));
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class SegmentMetadataClientTest method testTruncateWithSegmentTruncationException.
@Test(timeout = 10000)
public void testTruncateWithSegmentTruncationException() throws ConnectionFailedException {
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, true);
@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);
AtomicLong requestId = new AtomicLong();
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.TruncateSegment truncateSegment = invocation.getArgument(0);
processor.process(new SegmentIsTruncated(truncateSegment.getRequestId(), segment.getScopedName(), 124L, "", 124L));
requestId.set(truncateSegment.getRequestId());
return null;
}
}).when(connection).send(any(WireCommands.TruncateSegment.class));
client.truncateSegment(123L).join();
Mockito.verify(connection).send(Mockito.eq(new WireCommands.TruncateSegment(requestId.get(), segment.getScopedName(), 123L, "")));
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class CommandEncoderTest method testAppendSizeQueuedBreak.
@Test
public void testAppendSizeQueuedBreak() throws IOException {
AppendBatchSizeTracker batchSizeTracker = new FixedBatchSizeTracker(100);
DecodingOutputStream output = new DecodingOutputStream();
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
CommandEncoder commandEncoder = new CommandEncoder(x -> batchSizeTracker, null, output, null, endpoint);
UUID writerId1 = UUID.randomUUID();
WireCommand setupAppend = new WireCommands.SetupAppend(0, writerId1, "seg", "");
commandEncoder.write(setupAppend);
assertEquals(output.decoded.remove(0), setupAppend);
UUID writerId2 = UUID.randomUUID();
setupAppend = new WireCommands.SetupAppend(0, writerId2, "seg", "");
commandEncoder.write(setupAppend);
assertEquals(output.decoded.remove(0), setupAppend);
ByteBuf data = Unpooled.wrappedBuffer(new byte[40]);
WireCommands.Event event = new WireCommands.Event(data);
Append append1 = new Append("seg", writerId1, 1, event, 0);
commandEncoder.write(append1);
Append appendOther1 = new Append("seg", writerId2, 101, event, 0);
WireCommands.Event largeEvent = new WireCommands.Event(Unpooled.wrappedBuffer(new byte[CommandEncoder.MAX_QUEUED_SIZE]));
Append appendOther2 = new Append("seg", writerId2, 102, largeEvent, 0);
commandEncoder.write(appendOther1);
commandEncoder.write(appendOther2);
AppendBlock block = (AppendBlock) output.decoded.remove(0);
assertEquals(108, block.getData().readableBytes());
AppendBlockEnd blockEnd = (AppendBlockEnd) output.decoded.remove(0);
assertEquals(writerId1, blockEnd.getWriterId());
assertEquals(48, blockEnd.getSizeOfWholeEvents());
assertEquals(0, blockEnd.getData().readableBytes());
assertEquals(1, blockEnd.getNumEvents());
block = (AppendBlock) output.decoded.remove(0);
assertEquals(CommandEncoder.MAX_QUEUED_SIZE + 48 + 8, block.getData().readableBytes());
blockEnd = (AppendBlockEnd) output.decoded.remove(0);
assertEquals(writerId2, blockEnd.getWriterId());
assertEquals(CommandEncoder.MAX_QUEUED_SIZE + 48 + 8, blockEnd.getSizeOfWholeEvents());
assertEquals(0, blockEnd.getData().readableBytes());
assertEquals(2, blockEnd.getNumEvents());
}
Aggregations