public static WireCommand readFrom(DataInput in, int length) throws IOException { long requestId = in.readLong(); String segment = in.readUTF(); return new SegmentDeleted(requestId, segment); } }
})); processor.deleteSegment(new WireCommands.DeleteSegment(3, transactionName, "")); order.verify(connection).send(new WireCommands.SegmentDeleted(3, transactionName)); processor.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(4, transactionName, "")); order.verify(connection)
order.verify(connection).send(new WireCommands.SegmentTruncated(4, streamSegmentName)); order.verify(connection).send(new WireCommands.SegmentIsTruncated(5, streamSegmentName, truncateOffset, "")); order.verify(connection).send(new WireCommands.SegmentDeleted(6, streamSegmentName)); order.verifyNoMoreInteractions();
@Test public void testDeleteTableSegment() { MockConnectionFactory factory = new MockConnectionFactory(); // On receiving NoSuchSegment true should be returned. CompletableFuture<Boolean> result = helper.deleteTableSegment("", "", true, new MockHostControllerStore(), factory, "", System.nanoTime()); factory.rp.noSuchSegment(new WireCommands.NoSuchSegment(0, getQualifiedStreamSegmentName("", "", 0L), "")); assertTrue(result.join()); // On receiving SegmentDeleted true should be returned. result = helper.deleteTableSegment("", "", true, new MockHostControllerStore(), factory, "", System.nanoTime()); factory.rp.segmentDeleted(new WireCommands.SegmentDeleted(0, getQualifiedStreamSegmentName("", "", 0L))); assertTrue(result.join()); // On receiving TableSegmentNotEmpty WireCommandFailedException is thrown. result = helper.deleteTableSegment("", "", true, new MockHostControllerStore(), factory, "", System.nanoTime()); factory.rp.tableSegmentNotEmpty(new WireCommands.TableSegmentNotEmpty(0, getQualifiedStreamSegmentName("", "", 0L), "")); AssertExtensions.assertThrows("", result::join, ex -> ex instanceof WireCommandFailedException && (((WireCommandFailedException) ex).getReason() == WireCommandFailedException.Reason.TableSegmentNotEmpty)); Supplier<CompletableFuture<?>> futureSupplier = () -> helper.deleteTableSegment("", "", true, new MockHostControllerStore(), factory, "", System.nanoTime()); validateAuthTokenCheckFailed(factory, futureSupplier); validateWrongHost(factory, futureSupplier); validateConnectionDropped(factory, futureSupplier); validateProcessingFailure(factory, futureSupplier); }
@Test(timeout = 30000) public void testDeleteTableWithoutData() throws Exception { // Set up PravegaRequestProcessor instance to execute requests against val rnd = new Random(0); String streamSegmentName = "testTable1"; @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig()); serviceBuilder.initialize(); StreamSegmentStore store = serviceBuilder.createStreamSegmentService(); TableStore tableStore = serviceBuilder.createTableStoreService(); ServerConnection connection = mock(ServerConnection.class); InOrder order = inOrder(connection); PravegaRequestProcessor processor = new PravegaRequestProcessor(store, tableStore, connection); // Generate keys. ArrayList<HashedArray> keys = generateKeys(2, rnd); // Create a table segment. processor.createTableSegment(new WireCommands.CreateTableSegment(1, streamSegmentName, "")); order.verify(connection).send(new WireCommands.SegmentCreated(1, streamSegmentName)); processor.deleteTableSegment(new WireCommands.DeleteTableSegment(2, streamSegmentName, true, "")); order.verify(connection).send(new WireCommands.SegmentDeleted(2, streamSegmentName)); }
@Override public void deleteSegment(DeleteSegment deleteSegment) { String segment = deleteSegment.getSegment(); final String operation = "deleteSegment"; if (!verifyToken(segment, deleteSegment.getRequestId(), deleteSegment.getDelegationToken(), operation)) { return; } log.info(deleteSegment.getRequestId(), "Deleting segment {} ", deleteSegment); segmentStore.deleteStreamSegment(segment, TIMEOUT) .thenRun(() -> { connection.send(new SegmentDeleted(deleteSegment.getRequestId(), segment)); dynamicLogger.freezeCounter(nameFromSegment(SEGMENT_WRITE_BYTES, segment)); dynamicLogger.freezeCounter(nameFromSegment(SEGMENT_WRITE_EVENTS, segment)); dynamicLogger.freezeCounter(nameFromSegment(SEGMENT_READ_BYTES, segment)); }) .exceptionally(e -> handleException(deleteSegment.getRequestId(), segment, operation, e)); }
@Test public void testSegmentDeleted() throws IOException { testCommand(new WireCommands.SegmentDeleted(l, testString1)); }
@Override public void deleteTableSegment(final DeleteTableSegment deleteTableSegment) { String segment = deleteTableSegment.getSegment(); final String operation = "deleteTableSegment"; if (!verifyToken(segment, deleteTableSegment.getRequestId(), deleteTableSegment.getDelegationToken(), operation)) { return; } log.info(deleteTableSegment.getRequestId(), "Deleting table segment {}.", deleteTableSegment); tableStore.deleteSegment(segment, deleteTableSegment.isMustBeEmpty(), TIMEOUT) .thenRun(() -> connection.send(new SegmentDeleted(deleteTableSegment.getRequestId(), segment))) .exceptionally(e -> handleException(deleteTableSegment.getRequestId(), segment, operation, e)); }