Search in sources :

Example 6 with CommandArgs

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());
}
Also used : CommandArgs(io.pravega.cli.admin.CommandArgs) AttributeUpdateCollection(io.pravega.segmentstore.contracts.AttributeUpdateCollection) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) Properties(java.util.Properties) UUID(java.util.UUID) AdminCommandState(io.pravega.cli.admin.AdminCommandState) Test(org.junit.Test)

Example 7 with CommandArgs

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()));
}
Also used : CommandArgs(io.pravega.cli.admin.CommandArgs) DataCorruptionException(io.pravega.segmentstore.server.DataCorruptionException) Test(org.junit.Test)

Example 8 with CommandArgs

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);
}
Also used : CommandArgs(io.pravega.cli.admin.CommandArgs) ArrayList(java.util.ArrayList) Operation(io.pravega.segmentstore.server.logs.operations.Operation) DataCorruptionException(io.pravega.segmentstore.server.DataCorruptionException) Test(org.junit.Test)

Example 9 with CommandArgs

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());
}
Also used : CommandArgs(io.pravega.cli.admin.CommandArgs) DurableDataLogException(io.pravega.segmentstore.storage.DurableDataLogException) Test(org.junit.Test)

Example 10 with CommandArgs

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);
}
Also used : CommandArgs(io.pravega.cli.admin.CommandArgs) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Aggregations

CommandArgs (io.pravega.cli.admin.CommandArgs)18 Test (org.junit.Test)16 Properties (java.util.Properties)12 AdminCommandState (io.pravega.cli.admin.AdminCommandState)11 SegmentProperties (io.pravega.segmentstore.contracts.SegmentProperties)10 Cleanup (lombok.Cleanup)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 lombok.val (lombok.val)4 TestUtils (io.pravega.cli.admin.utils.TestUtils)3 AttributeUpdateCollection (io.pravega.segmentstore.contracts.AttributeUpdateCollection)3 DeleteSegmentOperation (io.pravega.segmentstore.server.logs.operations.DeleteSegmentOperation)3 BookKeeperLogFactory (io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory)3 UUID (java.util.UUID)3 Parser (io.pravega.cli.admin.Parser)2 CompositeByteArraySegment (io.pravega.common.util.CompositeByteArraySegment)2 ImmutableDate (io.pravega.common.util.ImmutableDate)2 AttributeId (io.pravega.segmentstore.contracts.AttributeId)2 AttributeUpdate (io.pravega.segmentstore.contracts.AttributeUpdate)2 DataCorruptionException (io.pravega.segmentstore.server.DataCorruptionException)2