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()); long newValue = in.readLong(); long excpecteValue = in.readLong(); String delegationToken = in.readUTF(); return new UpdateSegmentAttribute(requestId, segment, attributeId, newValue, excpecteValue, delegationToken); } }
private CompletableFuture<SegmentAttributeUpdated> updatePropertyAsync(UUID attributeId, long expected, long value, String delegationToken) { long requestId = requestIdGenerator.get(); log.trace("Updating segment attribute: {}", attributeId); RawClient connection = getConnection(); return connection.sendRequest(requestId, new UpdateSegmentAttribute(requestId, segmentId.getScopedName(), attributeId, value, expected, delegationToken)) .thenApply(r -> transformReply(r, SegmentAttributeUpdated.class)); }
@Test public void updateSegmentAttribute() { processor.updateSegmentAttribute(new WireCommands.UpdateSegmentAttribute(100L, "segment", null, 0, 0, "token")); verify(connection).send(new WireCommands.AuthTokenCheckFailed(100L, "")); }
order.verify(connection).send(new WireCommands.SegmentAttribute(2, WireCommands.NULL_ATTRIBUTE_VALUE)); processor.updateSegmentAttribute(new WireCommands.UpdateSegmentAttribute(2, streamSegmentName, attribute, 1, WireCommands.NULL_ATTRIBUTE_VALUE, "")); order.verify(connection).send(new WireCommands.SegmentAttributeUpdated(2, true)); processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(3, streamSegmentName, attribute, "")); order.verify(connection).send(new WireCommands.SegmentAttribute(3, 1)); processor.updateSegmentAttribute(new WireCommands.UpdateSegmentAttribute(4, streamSegmentName, attribute, 5, WireCommands.NULL_ATTRIBUTE_VALUE, "")); order.verify(connection).send(new WireCommands.SegmentAttributeUpdated(4, false)); processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(5, streamSegmentName, attribute, "")); order.verify(connection).send(new WireCommands.SegmentAttribute(5, 1)); processor.updateSegmentAttribute(new WireCommands.UpdateSegmentAttribute(6, streamSegmentName, attribute, 10, 1, "")); order.verify(connection).send(new WireCommands.SegmentAttributeUpdated(6, true)); processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(7, streamSegmentName, attribute, "")); order.verify(connection).send(new WireCommands.SegmentAttribute(7, 10)); processor.updateSegmentAttribute(new WireCommands.UpdateSegmentAttribute(8, streamSegmentName, attribute, WireCommands.NULL_ATTRIBUTE_VALUE, 10, "")); order.verify(connection).send(new WireCommands.SegmentAttributeUpdated(8, true)); processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(9, streamSegmentName, attribute, ""));
@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); @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 SegmentAttributeUpdated(1, true)); return null; } }).when(connection).sendAsync(Mockito.eq(new WireCommands.UpdateSegmentAttribute(1, segment.getScopedName(), attributeId, 1234, -1234, "")), Mockito.any(ClientConnection.CompletedCallback.class)); assertTrue(client.compareAndSetAttribute(SegmentAttribute.RevisionStreamClientMark, -1234, 1234)); }
@Test public void testUpdateSegmentAttribute() throws IOException { testCommand(new WireCommands.UpdateSegmentAttribute(l, testString1, uuid, l, l, "")); }