Skip to content

Commit

Permalink
[IGNITE-22091] Implement CLI for disaster recovery: partition states (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillippko committed May 3, 2024
1 parent ef50f41 commit 0a46272
Show file tree
Hide file tree
Showing 22 changed files with 1,159 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ public static class DisasterRecovery {
/** Disaster recovery group. */
public static final ErrorGroup RECOVERY_ERR_GROUP = registerGroup("RECOVERY", (short) 20);

/** Partitions were not found. */
public static final int PARTITIONS_NOT_FOUND_ERR = RECOVERY_ERR_GROUP.registerErrorCode((short) 1);
/** Partition ID is not in valid range. */
public static final int ILLEGAL_PARTITION_ID_ERR = RECOVERY_ERR_GROUP.registerErrorCode((short) 1);

/** Nodes were not found. */
public static final int NODES_NOT_FOUND_ERR = RECOVERY_ERR_GROUP.registerErrorCode((short) 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.StringWriter;
import java.io.Writer;
import java.util.List;
import java.util.Set;
import org.apache.ignite.internal.Cluster;
import org.apache.ignite.internal.ClusterPerClassIntegrationTest;
import org.apache.ignite.internal.cli.call.connect.ConnectCall;
Expand Down Expand Up @@ -145,18 +146,65 @@ protected void assertOutputIs(String expectedOutput) {
.isEqualTo(expectedOutput);
}

protected void assertOutputStartsWith(String expectedOutput) {
assertThat(sout.toString())
.as("Expected command output to start with: " + expectedOutput + " but was " + sout.toString())
.startsWith(expectedOutput);
}

protected void assertOutputContains(String expectedOutput) {
assertThat(sout.toString())
.as("Expected command output to contain: " + expectedOutput + " but was " + sout.toString())
.contains(expectedOutput);
}

protected void assertOutputContainsAnyIgnoringCase(Set<String> expectedOutput) {
CharSequence[] expectedUpperCase = expectedOutput.stream().map(String::toUpperCase).toArray(CharSequence[]::new);

assertThat(sout.toString().toUpperCase())
.as("Expected command output to contain any of, ignoring case: " + expectedOutput + " but was " + sout.toString())
.containsAnyOf(expectedUpperCase);
}

protected void assertOutputContainsAny(Set<String> expectedOutput) {

assertThat(sout.toString())
.as("Expected command output to contain any of: " + expectedOutput + " but was " + sout.toString())
.containsAnyOf(expectedOutput.toArray(CharSequence[]::new));
}

protected void assertOutputContainsAllIgnoringCase(Set<String> expectedOutput) {
CharSequence[] expectedUpperCase = expectedOutput.stream().map(String::toUpperCase).toArray(CharSequence[]::new);

assertThat(sout.toString().toUpperCase())
.as("Expected command output to contain all of, ignoring case: " + expectedOutput + " but was " + sout.toString())
.contains(expectedUpperCase);
}

protected void assertOutputContainsAll(Set<String> expectedOutput) {
assertThat(sout.toString())
.as("Expected command output to contain all of: " + expectedOutput + " but was " + sout.toString())
.contains(expectedOutput.toArray(CharSequence[]::new));
}

protected void assertOutputDoesNotContain(String expectedOutput) {
assertThat(sout.toString())
.as("Expected command output to not contain: " + expectedOutput + " but was " + sout.toString())
.doesNotContain(expectedOutput);
}

protected void assertOutputDoesNotContain(Set<String> expectedOutput) {
assertThat(sout.toString())
.as("Expected command output to not contain: " + expectedOutput + " but was " + sout.toString())
.doesNotContain(expectedOutput.toArray(CharSequence[]::new));
}

protected void assertOutputDoesNotContainIgnoreCase(Set<String> expectedOutput) {
assertThat(sout.toString())
.as("Expected command output to not contain: " + expectedOutput + " but was " + sout.toString())
.doesNotContainIgnoringCase(expectedOutput.toArray(CharSequence[]::new));
}

protected void assertOutputMatches(String regex) {
assertThat(sout.toString())
.as("Expected command output to match regex: " + regex + " but it is not: " + sout.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
* limitations under the License.
*/

package org.apache.ignite.internal.table.distributed.disaster.exceptions;
package org.apache.ignite.internal.cli.commands.recovery;

import static org.apache.ignite.lang.ErrorGroups.DisasterRecovery.PARTITIONS_NOT_FOUND_ERR;
import java.util.List;
import org.apache.ignite.internal.cli.commands.recovery.partitions.PartitionStatesCommand;
import org.apache.ignite.internal.util.CollectionUtils;

import java.util.Set;
/** Test class for {@link PartitionStatesCommand}. */
public class ItPartitionStatesCommandTest extends ItPartitionStatesTest {

/** Exception is thrown when appropriate partition can`t be found. */
public class PartitionsNotFoundException extends DisasterRecoveryException {
private static final long serialVersionUID = -9215416423159317425L;
@Override
protected void execute(String... args) {
String[] fullArgs = CollectionUtils.concat(List.of("recovery", "partition-states"), List.of(args)).toArray(String[]::new);

public PartitionsNotFoundException(Set<Integer> missingPartitionIds) {
super(PARTITIONS_NOT_FOUND_ERR, "Some partitions are missing: " + missingPartitionIds);
super.execute(fullArgs);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.internal.cli.commands.recovery;

import org.apache.ignite.internal.cli.commands.recovery.partitions.PartitionStatesReplCommand;

/** Test class for {@link PartitionStatesReplCommand}. */
public class ItPartitionStatesReplCommandTest extends ItPartitionStatesTest {

@Override
protected Class<?> getCommandClass() {
return PartitionStatesReplCommand.class;
}
}

0 comments on commit 0a46272

Please sign in to comment.