use of io.pravega.cli.admin.CommandArgs in project pravega by pravega.
the class DataRecoveryTest method testRepairLogEditOperationCreateAttributeUpdateCollection.
@Test
public void testRepairLogEditOperationCreateAttributeUpdateCollection() throws IOException {
// Setup command object.
STATE.set(new AdminCommandState());
Properties pravegaProperties = new Properties();
pravegaProperties.setProperty("pravegaservice.container.count", "1");
pravegaProperties.setProperty("pravegaservice.clusterName", "pravega0");
STATE.get().getConfigBuilder().include(pravegaProperties);
CommandArgs args = new CommandArgs(List.of("0"), STATE.get());
DurableDataLogRepairCommand command = Mockito.spy(new DurableDataLogRepairCommand(args));
// Create an AttributeUpdateCollection via the command logic and check the expected output.
AttributeUpdateCollection attributeUpdates = new AttributeUpdateCollection();
UUID uuid = UUID.randomUUID();
attributeUpdates.add(new AttributeUpdate(AttributeId.fromUUID(uuid), AttributeUpdateType.Replace, 1, 2));
Mockito.doReturn(true).doReturn(false).when(command).confirmContinue();
Mockito.doReturn(uuid.toString()).when(command).getStringUserInput(Mockito.any());
Mockito.doReturn(1L).doReturn(2L).doReturn(1L).when(command).getLongUserInput(Mockito.any());
Mockito.doReturn((int) AttributeUpdateType.Replace.getTypeId()).when(command).getIntUserInput(Mockito.any());
Assert.assertArrayEquals(attributeUpdates.getUUIDAttributeUpdates().toArray(), command.createAttributeUpdateCollection().getUUIDAttributeUpdates().toArray());
// Induce exceptions during the process to check error handling.
Mockito.doReturn(true).doReturn(true).doReturn(false).when(command).confirmContinue();
Mockito.doThrow(NumberFormatException.class).doThrow(NullPointerException.class).when(command).getStringUserInput(Mockito.any());
Assert.assertArrayEquals(new Object[0], command.createAttributeUpdateCollection().getUUIDAttributeUpdates().toArray());
}
use of io.pravega.cli.admin.CommandArgs in project pravega by pravega.
the class BookkeeperCommandsTest method testBookKeeperRecoveryCommand.
@Test
public void testBookKeeperRecoveryCommand() throws Exception {
createLedgerInBookkeeperTestCluster(0);
String commandResult = TestUtils.executeCommand("container recover 0", STATE.get());
Assert.assertTrue(commandResult.contains("Recovery complete"));
CommandArgs args = new CommandArgs(Collections.singletonList("0"), STATE.get());
ContainerRecoverCommand command = new ContainerRecoverCommand(args);
// Test unwrap exception options.
command.unwrapDataCorruptionException(new DataCorruptionException("test"));
command.unwrapDataCorruptionException(new DataCorruptionException("test", "test"));
command.unwrapDataCorruptionException(new DataCorruptionException("test", Arrays.asList("test", "test")));
command.unwrapDataCorruptionException(new DataCorruptionException("test", (DataCorruptionException) null));
// Check that exception is thrown if ZK is not available.
this.zkUtil.stopCluster();
AssertExtensions.assertThrows(DataLogNotAvailableException.class, () -> TestUtils.executeCommand("container recover 0", STATE.get()));
}
use of io.pravega.cli.admin.CommandArgs in project pravega by pravega.
the class BookkeeperCommandsTest method testRecoveryState.
@Test
public void testRecoveryState() {
CommandArgs args = new CommandArgs(Collections.singletonList("0"), STATE.get());
ContainerRecoverCommand.RecoveryState state = new ContainerRecoverCommand(args).new RecoveryState();
Operation op = new TestOperation();
List<DataFrameRecord.EntryInfo> entries = new ArrayList<>();
entries.add(new TestEntryInfo());
// Exercise RecoveryState logic.
state.operationComplete(op, new DataCorruptionException("Test exception"));
state.newOperation(op, entries);
state.operationComplete(op, null);
}
use of io.pravega.cli.admin.CommandArgs in project pravega by pravega.
the class BookkeeperCommandsTest method testBookKeeperContinuousRecoveryCommand.
@Test
public void testBookKeeperContinuousRecoveryCommand() throws Exception {
createLedgerInBookkeeperTestCluster(0);
String commandResult = TestUtils.executeCommand("container continuous-recover 2 1", STATE.get());
Assert.assertTrue(commandResult.contains("Recovery complete"));
CommandArgs args = new CommandArgs(Arrays.asList("1", "1"), STATE.get());
ContainerContinuousRecoveryCommand command = Mockito.spy(new ContainerContinuousRecoveryCommand(args));
Mockito.doThrow(new DurableDataLogException("Intentional")).when(command).performRecovery(ArgumentMatchers.anyInt());
command.execute();
Assert.assertNotNull(ContainerContinuousRecoveryCommand.descriptor());
}
use of io.pravega.cli.admin.CommandArgs in project pravega by pravega.
the class BookkeeperCommandsTest method testBookKeeperCleanupCommand.
@Test
public void testBookKeeperCleanupCommand() throws Exception {
createLedgerInBookkeeperTestCluster(0);
System.setIn(new ByteArrayInputStream("yes".getBytes()));
String commandResult = TestUtils.executeCommand("bk cleanup", STATE.get());
Assert.assertTrue(commandResult.contains("no Ledgers eligible for deletion"));
System.setIn(new ByteArrayInputStream("no".getBytes()));
TestUtils.executeCommand("bk cleanup", STATE.get());
CommandArgs args = new CommandArgs(Collections.singletonList(""), STATE.get());
BookKeeperCleanupCommand command = new BookKeeperCleanupCommand(args);
BookKeeperCommand.Context context = command.createContext();
// List one existing and one
command.listCandidates(Collections.singletonList(0L), context);
Assert.assertFalse(outContent.toString().contains("No such ledger exists"));
command.listCandidates(Collections.singletonList(1L), context);
Assert.assertTrue(outContent.toString().contains("No such ledger exists"));
// Try to exercise deletion standalone.
command.deleteCandidates(Collections.singletonList(0L), Collections.singletonList(0L), context);
command.deleteCandidates(Collections.singletonList(0L), Collections.singletonList(1L), context);
Assert.assertTrue(outContent.toString().contains("Deleted Ledger 0"));
command.deleteCandidates(Collections.singletonList(-1L), Collections.singletonList(0L), context);
command.deleteCandidates(Collections.singletonList(0L), Collections.singletonList(1L), null);
}
Aggregations