Skip to content

Commit 9a87afe

Browse files
committed
Make IT generic
Signed-off-by: Lakshya Taragi <lakshya.taragi@gmail.com>
1 parent ddc8fb2 commit 9a87afe

File tree

1 file changed

+46
-25
lines changed

1 file changed

+46
-25
lines changed

server/src/internalClusterTest/java/org/opensearch/remotemigration/RemoteStoreMigrationShardAllocationIT.java

+46-25
Original file line numberDiff line numberDiff line change
@@ -27,61 +27,80 @@ public class RemoteStoreMigrationShardAllocationIT extends RemoteStoreMigrationS
2727
private Client client;
2828

2929
// test for shard allocation decisions for MIXED mode and NONE direction
30-
public void testAllocationForRemoteStoreBackedIndexForNoneDirectionAndMixedMode() throws Exception {
30+
public void testAllocationForNoneDirectionAndMixedMode() throws Exception {
31+
boolean isRemoteStoreBackedIndex = randomBoolean();
32+
boolean isReplicaAllocation = randomBoolean();
33+
logger.info(
34+
String.format(
35+
Locale.ROOT,
36+
"Test for allocation decisions for %s shard of a %s store backed index under NONE direction",
37+
(isReplicaAllocation ? "replica" : "primary"),
38+
(isRemoteStoreBackedIndex ? "remote" : "non remote")
39+
)
40+
);
41+
3142
logger.info("Initialize cluster");
32-
initializeCluster(true);
43+
initializeCluster(isRemoteStoreBackedIndex);
3344

3445
logger.info("Add data nodes");
35-
String remoteNodeName1 = internalCluster().startDataOnlyNode();
36-
String remoteNodeName2 = internalCluster().startDataOnlyNode();
46+
String previousNodeName1 = internalCluster().startDataOnlyNode();
47+
String previousNodeName2 = internalCluster().startDataOnlyNode();
3748
internalCluster().validateClusterFormed();
38-
DiscoveryNode remoteNode1 = assertNodeInCluster(remoteNodeName1);
39-
DiscoveryNode remoteNode2 = assertNodeInCluster(remoteNodeName2);
49+
DiscoveryNode previousNode1 = assertNodeInCluster(previousNodeName1);
50+
DiscoveryNode previousNode2 = assertNodeInCluster(previousNodeName2);
4051

4152
logger.info("Prepare test index");
42-
boolean isReplicaAllocation = randomBoolean();
4353
if (isReplicaAllocation) {
44-
prepareIndexWithAllocatedPrimary(remoteNode1, Optional.empty());
54+
prepareIndexWithAllocatedPrimary(previousNode1, Optional.empty());
4555
} else {
4656
prepareIndexWithoutReplica(Optional.empty());
4757
}
48-
assertRemoteStoreBackedIndex(TEST_INDEX);
58+
59+
if (isRemoteStoreBackedIndex) {
60+
assertRemoteStoreBackedIndex(TEST_INDEX);
61+
} else {
62+
assertNonRemoteStoreBackedIndex(TEST_INDEX);
63+
}
4964

5065
logger.info("Switch to MIXED cluster compatibility mode");
5166
setClusterMode(MIXED.mode);
52-
addRemote = false;
53-
String docrepNodeName = internalCluster().startDataOnlyNode();
67+
addRemote = !addRemote;
68+
String newNodeName = internalCluster().startDataOnlyNode();
5469
internalCluster().validateClusterFormed();
55-
DiscoveryNode docrepNode = assertNodeInCluster(docrepNodeName);
70+
DiscoveryNode newNode = assertNodeInCluster(newNodeName);
5671

57-
logger.info("Verify decision for allocation on docrep node");
72+
logger.info("Verify decision for allocation on the new node");
5873
prepareDecisions();
59-
Decision decision = getDecisionForTargetNode(docrepNode, !isReplicaAllocation, false, false);
74+
Decision decision = getDecisionForTargetNode(newNode, !isReplicaAllocation, false, false);
6075
assertEquals(Decision.Type.NO, decision.type());
6176
String expectedReason = String.format(
6277
Locale.ROOT,
63-
"[none migration_direction]: %s shard copy can not be allocated to a non-remote node for remote store backed index",
64-
(isReplicaAllocation ? "replica" : "primary")
78+
"[none migration_direction]: %s shard copy can not be allocated to a %s node for %s store backed index",
79+
(isReplicaAllocation ? "replica" : "primary"),
80+
(isRemoteStoreBackedIndex ? "non-remote" : "remote"),
81+
(isRemoteStoreBackedIndex ? "remote" : "non remote")
6582
);
6683
assertEquals(expectedReason, decision.getExplanation().toLowerCase(Locale.ROOT));
6784

68-
logger.info("Attempt allocation of shard on non-remote node");
69-
attemptAllocation(docrepNodeName);
85+
logger.info("Attempt allocation of shard on new node");
86+
attemptAllocation(newNodeName);
7087

7188
logger.info("Verify non-allocation of shard");
7289
assertNonAllocation(!isReplicaAllocation);
7390

74-
logger.info("Verify decision for allocation on remote node");
75-
decision = getDecisionForTargetNode(remoteNode2, !isReplicaAllocation, true, false);
91+
logger.info("Verify decision for allocation on previous node");
92+
decision = getDecisionForTargetNode(previousNode2, !isReplicaAllocation, true, false);
7693
assertEquals(Decision.Type.YES, decision.type());
7794
expectedReason = String.format(
7895
Locale.ROOT,
79-
"[none migration_direction]: %s shard copy can be allocated to a remote node for remote store backed index",
80-
(isReplicaAllocation ? "replica" : "primary")
96+
"[none migration_direction]: %s shard copy can be allocated to a %s node for %s store backed index",
97+
(isReplicaAllocation ? "replica" : "primary"),
98+
(isRemoteStoreBackedIndex ? "remote" : "non-remote"),
99+
(isRemoteStoreBackedIndex ? "remote" : "non remote")
81100
);
82101
assertEquals(expectedReason, decision.getExplanation().toLowerCase(Locale.ROOT));
83102

84-
logger.info("Attempt free allocation of shard on remote node");
103+
logger.info("Attempt free allocation of shard");
85104
attemptAllocation(null);
86105

87106
logger.info("Verify successful allocation of shard");
@@ -91,9 +110,11 @@ public void testAllocationForRemoteStoreBackedIndexForNoneDirectionAndMixedMode(
91110
ensureYellowAndNoInitializingShards(TEST_INDEX);
92111
}
93112
assertAllocation(!isReplicaAllocation, null);
94-
logger.info("Verify allocation on one of the remote nodes");
113+
logger.info("Verify allocation on one of the previous nodes");
95114
ShardRouting shardRouting = getShardRouting(!isReplicaAllocation);
96-
assertTrue(shardRouting.currentNodeId().equals(remoteNode1.getId()) || shardRouting.currentNodeId().equals(remoteNode2.getId()));
115+
assertTrue(
116+
shardRouting.currentNodeId().equals(previousNode1.getId()) || shardRouting.currentNodeId().equals(previousNode2.getId())
117+
);
97118
}
98119

99120
// bootstrap a cluster

0 commit comments

Comments
 (0)