public static WireCommand readFrom(DataInput in, int length) throws IOException { long requestId = in.readLong(); String segment = in.readUTF(); UUID attributeId = new UUID(in.readLong(), in.readLong()); String delegationToken = in.readUTF(); return new GetSegmentAttribute(requestId, segment, attributeId, delegationToken); } }
order.verify(connection).send(new WireCommands.SegmentCreated(1, streamSegmentName)); processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(2, streamSegmentName, attribute, "")); order.verify(connection).send(new WireCommands.SegmentAttribute(2, WireCommands.NULL_ATTRIBUTE_VALUE)); processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(3, streamSegmentName, attribute, "")); order.verify(connection).send(new WireCommands.SegmentAttribute(3, 1)); processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(5, streamSegmentName, attribute, "")); order.verify(connection).send(new WireCommands.SegmentAttribute(5, 1)); processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(7, streamSegmentName, attribute, "")); order.verify(connection).send(new WireCommands.SegmentAttribute(7, 10)); processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(9, streamSegmentName, attribute, "")); order.verify(connection).send(new WireCommands.SegmentAttribute(9, WireCommands.NULL_ATTRIBUTE_VALUE));
@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).sendAsync(Mockito.eq(new WireCommands.GetSegmentAttribute(1, segment.getScopedName(), attributeId, "")), Mockito.any(ClientConnection.CompletedCallback.class)); long value = client.fetchProperty(SegmentAttribute.RevisionStreamClientMark); assertEquals(123, value); }
@Override public void getSegmentAttribute(GetSegmentAttribute getSegmentAttribute) { long requestId = getSegmentAttribute.getRequestId(); String segmentName = getSegmentAttribute.getSegmentName(); UUID attributeId = getSegmentAttribute.getAttributeId(); final String operation = "getSegmentAttribute"; if (!verifyToken(segmentName, getSegmentAttribute.getRequestId(), getSegmentAttribute.getDelegationToken(), operation)) { return; } long trace = LoggerHelpers.traceEnter(log, operation, getSegmentAttribute); segmentStore.getStreamSegmentInfo(segmentName, TIMEOUT) .thenAccept(properties -> { LoggerHelpers.traceLeave(log, operation, trace, properties); if (properties == null) { connection.send(new NoSuchSegment(requestId, segmentName, EMPTY_STACK_TRACE)); } else { Map<UUID, Long> attributes = properties.getAttributes(); Long value = attributes.get(attributeId); if (value == null) { value = WireCommands.NULL_ATTRIBUTE_VALUE; } connection.send(new SegmentAttribute(requestId, value)); } }) .exceptionally(e -> handleException(requestId, segmentName, operation, e)); }
@Test public void testGetSegmentAttribute() throws IOException { testCommand(new WireCommands.GetSegmentAttribute(l, testString1, uuid, "")); }
private CompletableFuture<WireCommands.SegmentAttribute> getPropertyAsync(UUID attributeId, String delegationToken) { long requestId = requestIdGenerator.get(); log.debug("Getting segment attribute: {}", attributeId); RawClient connection = getConnection(); return connection.sendRequest(requestId, new GetSegmentAttribute(requestId, segmentId.getScopedName(), attributeId, delegationToken)) .thenApply(r -> transformReply(r, WireCommands.SegmentAttribute.class)); }
@Test public void getSegmentAttribute() { processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(100L, "segment", null, "token")); verify(connection).send(new WireCommands.AuthTokenCheckFailed(100L, "")); }