public static SegmentHelper getSegmentHelperMock() { SegmentHelper helper = spy(new SegmentHelper()); doReturn(NodeUri.newBuilder().setEndpoint("localhost").setPort(SERVICE_PORT).build()).when(helper).getSegmentUri( anyString(), anyString(), anyLong(), any()); doReturn(CompletableFuture.completedFuture(true)).when(helper).sealSegment( anyString(), anyString(), anyLong(), any(), any(), any(), anyLong()); doReturn(CompletableFuture.completedFuture(true)).when(helper).createSegment( anyString(), anyString(), anyLong(), any(), any(), any(), any(), anyLong()); doReturn(CompletableFuture.completedFuture(true)).when(helper).deleteSegment( anyString(), anyString(), anyLong(), any(), any(), any(), anyLong()); doReturn(CompletableFuture.completedFuture(true)).when(helper).createTransaction( anyString(), anyString(), anyLong(), any(), any(), any(), any()); doReturn(CompletableFuture.completedFuture(true)).when(helper).abortTransaction( anyString(), anyString(), anyLong(), any(), any(), any(), any()); doReturn(CompletableFuture.completedFuture(true)).when(helper).commitTransaction( anyString(), anyString(), anyLong(), anyLong(), any(), any(), any(), any()); doReturn(CompletableFuture.completedFuture(true)).when(helper).updatePolicy( anyString(), anyString(), any(), anyLong(), any(), any(), any(), anyLong()); doReturn(CompletableFuture.completedFuture(true)).when(helper).truncateSegment( anyString(), anyString(), anyLong(), anyLong(), any(), any(), any(), anyLong()); doReturn(CompletableFuture.completedFuture(new WireCommands.StreamSegmentInfo(0L, "", true, true, false, 0L, 0L, 0L))).when(helper).getSegmentInfo( anyString(), anyString(), anyLong(), any(), any(), anyString()); return helper; }
order.verify(connection).send(new WireCommands.SegmentCreated(1, transactionName)); order.verify(connection).send(Mockito.argThat(t -> { return t instanceof WireCommands.StreamSegmentInfo && ((WireCommands.StreamSegmentInfo) t).exists(); })); processor.mergeSegments(new WireCommands.MergeSegments(3, streamSegmentName, transactionName, "")); processor.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(2, transactionName, "")); order.verify(connection).send(Mockito.argThat(t -> { return t instanceof WireCommands.StreamSegmentInfo && ((WireCommands.StreamSegmentInfo) t).exists(); })); processor.deleteSegment(new WireCommands.DeleteSegment(3, transactionName, ""));
@Override public void getStreamSegmentInfo(GetStreamSegmentInfo getStreamSegmentInfo) { String segmentName = getStreamSegmentInfo.getSegmentName(); final String operation = "getStreamSegmentInfo"; if (!verifyToken(segmentName, getStreamSegmentInfo.getRequestId(), getStreamSegmentInfo.getDelegationToken(), operation)) { return; } segmentStore.getStreamSegmentInfo(segmentName, TIMEOUT) .thenAccept(properties -> { if (properties != null) { StreamSegmentInfo result = new StreamSegmentInfo(getStreamSegmentInfo.getRequestId(), properties.getName(), true, properties.isSealed(), properties.isDeleted(), properties.getLastModified().getTime(), properties.getLength(), properties.getStartOffset()); log.trace("Read stream segment info: {}", result); connection.send(result); } else { log.trace("getStreamSegmentInfo could not find segment {}", segmentName); connection.send(new StreamSegmentInfo(getStreamSegmentInfo.getRequestId(), segmentName, false, true, true, 0, 0, 0)); } }) .exceptionally(e -> handleException(getStreamSegmentInfo.getRequestId(), segmentName, operation, e)); }
public static <T extends InputStream & DataInput> WireCommand readFrom(T in, int length) throws IOException { long requestId = in.readLong(); String segmentName = in.readUTF(); boolean exists = in.readBoolean(); boolean isSealed = in.readBoolean(); boolean isDeleted = in.readBoolean(); long lastModified = in.readLong(); long segmentLength = in.readLong(); long startOffset = 0; if (in.available() >= Long.BYTES) { // Versioning workaround until PDP-21 is implemented (https://github.com/pravega/pravega/issues/1948). startOffset = in.readLong(); } return new StreamSegmentInfo(requestId, segmentName, exists, isSealed, isDeleted, lastModified, segmentLength, startOffset); } }
@Test public void testStreamSegmentInfo() throws IOException { testCommand(new WireCommands.StreamSegmentInfo(l - 1, testString1, true, false, false, l, l + 1, l - 1)); }
@Override public Void answer(InvocationOnMock invocation) throws Throwable { GetStreamSegmentInfo request = (GetStreamSegmentInfo) invocation.getArgument(0); connectionFactory.getProcessor(location) .process(new StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0)); return null; } }).when(connection).sendAsync(Mockito.any(GetStreamSegmentInfo.class),
@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).sendAsync(Mockito.eq(new WireCommands.GetStreamSegmentInfo(1, segment.getScopedName(), "")),
@Override public Void answer(InvocationOnMock invocation) throws Throwable { ReplyProcessor processor = cf.getProcessor(endpoint); processor.process(new StreamSegmentInfo(2, segment.getScopedName(), true, false, false, 0, 123, 121)); return null; } }).when(connection).sendAsync(Mockito.eq(getSegmentInfo2), Mockito.any(ClientConnection.CompletedCallback.class));
@Override public Void answer(InvocationOnMock invocation) throws Throwable { WireCommands.GetStreamSegmentInfo request = (WireCommands.GetStreamSegmentInfo) invocation.getArgument(0); connectionFactory.getProcessor(location) .process(new WireCommands.StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0)); return null; } }).when(connection).sendAsync(Mockito.any(WireCommands.GetStreamSegmentInfo.class),
@Override public long fetchCurrentSegmentLength() { Exceptions.checkNotClosed(closed.get(), this); val future = RETRY_SCHEDULE.retryingOn(ConnectionFailedException.class) .throwingOn(NoSuchSegmentException.class) .runAsync(() -> getStreamSegmentInfo(delegationToken), connectionFactory.getInternalExecutor()); return Futures.getThrowingException(future).getWriteOffset(); }
@Override public SegmentInfo getSegmentInfo() { val future = RETRY_SCHEDULE.retryingOn(ConnectionFailedException.class) .throwingOn(NoSuchSegmentException.class) .runAsync(() -> getStreamSegmentInfo(delegationToken), connectionFactory.getInternalExecutor()); StreamSegmentInfo info = Futures.getThrowingException(future); return new SegmentInfo(segmentId, info.getStartOffset(), info.getWriteOffset(), info.isSealed(), info.getLastModified()); }
@Override public Void answer(InvocationOnMock invocation) throws Throwable { processor.get().process(new StreamSegmentInfo(3, segment.getScopedName(), true, false, false, 0, 123, 121)); return null; } }).when(connection2).sendAsync(Mockito.eq(getSegmentInfo2), Mockito.any(ClientConnection.CompletedCallback.class));
@Override public Void answer(InvocationOnMock invocation) throws Throwable { GetStreamSegmentInfo request = (GetStreamSegmentInfo) invocation.getArgument(0); connectionFactory.getProcessor(location) .process(new StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0)); return null; } }).when(connection).sendAsync(Mockito.any(GetStreamSegmentInfo.class),