@Test(timeout = 30000) public void testDeleteTableWithData() throws Exception { // Set up PravegaRequestProcessor instance to execute requests against val rnd = new Random(0); String streamSegmentName = "testTable"; @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 and add data. processor.createTableSegment(new WireCommands.CreateTableSegment(3, streamSegmentName, "")); order.verify(connection).send(new WireCommands.SegmentCreated(3, streamSegmentName)); TableEntry e1 = TableEntry.unversioned(keys.get(0), generateValue(rnd)); processor.updateTableEntries(new WireCommands.UpdateTableEntries(4, streamSegmentName, "", getTableEntries(singletonList(e1)))); order.verify(connection).send(new WireCommands.TableEntriesUpdated(4, singletonList(0L))); // Delete a table segment which has data. processor.deleteTableSegment(new WireCommands.DeleteTableSegment(5, streamSegmentName, true, "")); order.verify(connection).send(new WireCommands.TableSegmentNotEmpty(5, streamSegmentName, "")); }
@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); }
} else if (u instanceof TableSegmentNotEmptyException) { log.warn(requestId, "Table segment '{}' is not empty to perform '{}'.", segment, operation); invokeSafely(connection::send, new TableSegmentNotEmpty(requestId, segment, clientReplyStackTrace), failureHandler); } else if (u instanceof KeyNotExistsException) { log.warn(requestId, "Conditional update on Table segment '{}' failed as the key does not exist.", segment);
public static WireCommand readFrom(ByteBufInputStream in, int length) throws IOException { long requestId = in.readLong(); String segment = in.readUTF(); String serverStackTrace = in.readUTF(); return new TableSegmentNotEmpty(requestId, segment, serverStackTrace); }
@Test public void testNotEmptyTableSegment() throws IOException { WireCommands.TableSegmentNotEmpty cmd = new WireCommands.TableSegmentNotEmpty(l, testString1, "SomeException"); testCommand(cmd); assertTrue(cmd.isFailure()); }