Skip to content

Commit c7d86be

Browse files
committed
Integration test
Signed-off-by: Suraj Singh <surajrider@gmail.com>
1 parent c48d5df commit c7d86be

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java

+71-1
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,23 @@
3333
import org.opensearch.index.engine.Segment;
3434
import org.opensearch.index.shard.IndexShard;
3535
import org.opensearch.indices.IndicesService;
36+
import org.opensearch.indices.recovery.FileChunkRequest;
3637
import org.opensearch.indices.replication.common.ReplicationType;
38+
import org.opensearch.plugins.Plugin;
3739
import org.opensearch.test.BackgroundIndexer;
3840
import org.opensearch.test.InternalTestCluster;
3941
import org.opensearch.test.OpenSearchIntegTestCase;
42+
import org.opensearch.test.transport.MockTransportService;
43+
import org.opensearch.transport.TransportService;
4044

4145
import java.io.IOException;
46+
import java.util.Collection;
4247
import java.util.Arrays;
4348
import java.util.List;
4449
import java.util.Map;
45-
import java.util.Optional;
4650
import java.util.Set;
51+
import java.util.Optional;
52+
import java.util.concurrent.CountDownLatch;
4753
import java.util.concurrent.TimeUnit;
4854
import java.util.function.Function;
4955
import java.util.stream.Collectors;
@@ -65,6 +71,11 @@ public static void assumeFeatureFlag() {
6571
assumeTrue("Segment replication Feature flag is enabled", Boolean.parseBoolean(System.getProperty(FeatureFlags.REPLICATION_TYPE)));
6672
}
6773

74+
@Override
75+
protected Collection<Class<? extends Plugin>> nodePlugins() {
76+
return Arrays.asList(MockTransportService.TestPlugin.class);
77+
}
78+
6879
@Override
6980
public Settings indexSettings() {
7081
return Settings.builder()
@@ -318,6 +329,65 @@ public void testReplicationAfterForceMerge() throws Exception {
318329
}
319330
}
320331

332+
public void testCancellation() throws Exception {
333+
final String primaryNode = internalCluster().startNode();
334+
createIndex(INDEX_NAME, Settings.builder().put(indexSettings()).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1).build());
335+
ensureYellow(INDEX_NAME);
336+
337+
final String replicaNode = internalCluster().startNode();
338+
339+
final SegmentReplicationSourceService segmentReplicationSourceService = internalCluster().getInstance(
340+
SegmentReplicationSourceService.class,
341+
primaryNode
342+
);
343+
final IndexShard primaryShard = getIndexShard(primaryNode);
344+
345+
CountDownLatch latch = new CountDownLatch(1);
346+
347+
MockTransportService mockTransportService = ((MockTransportService) internalCluster().getInstance(
348+
TransportService.class,
349+
primaryNode
350+
));
351+
mockTransportService.addSendBehavior(
352+
internalCluster().getInstance(TransportService.class, replicaNode),
353+
(connection, requestId, action, request, options) -> {
354+
if (action.equals(SegmentReplicationTargetService.Actions.FILE_CHUNK)) {
355+
FileChunkRequest req = (FileChunkRequest) request;
356+
logger.debug("file chunk [{}] lastChunk: {}", req, req.lastChunk());
357+
if (req.name().endsWith("cfs") && req.lastChunk()) {
358+
try {
359+
latch.await();
360+
} catch (InterruptedException e) {
361+
throw new RuntimeException(e);
362+
}
363+
}
364+
}
365+
connection.sendRequest(requestId, action, request, options);
366+
}
367+
);
368+
369+
final int docCount = scaledRandomIntBetween(0, 200);
370+
try (
371+
BackgroundIndexer indexer = new BackgroundIndexer(
372+
INDEX_NAME,
373+
"_doc",
374+
client(),
375+
-1,
376+
RandomizedTest.scaledRandomIntBetween(2, 5),
377+
false,
378+
random()
379+
)
380+
) {
381+
indexer.start(docCount);
382+
waitForDocs(docCount, indexer);
383+
384+
flush(INDEX_NAME);
385+
}
386+
segmentReplicationSourceService.beforeIndexShardClosed(primaryShard.shardId(), primaryShard, indexSettings());
387+
latch.countDown();
388+
assertDocCounts(docCount, primaryNode);
389+
}
390+
321391
public void testStartReplicaAfterPrimaryIndexesDocs() throws Exception {
322392
final String primaryNode = internalCluster().startNode();
323393
createIndex(INDEX_NAME, Settings.builder().put(indexSettings()).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build());

server/src/test/java/org/opensearch/indices/replication/SegmentReplicationSourceHandlerTests.java

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import static org.mockito.Mockito.verify;
3737
import static org.mockito.Mockito.times;
3838

39-
4039
public class SegmentReplicationSourceHandlerTests extends IndexShardTestCase {
4140

4241
private final DiscoveryNode localNode = new DiscoveryNode("local", buildNewFakeTransportAddress(), Version.CURRENT);

0 commit comments

Comments
 (0)