Created
February 2, 2024 15:44
-
-
Save DiannaHohensee/f05ac2349e88978aed8e0953e7308239 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Before | |
public void setupTest() throws IOException { | |
indexNode = startMasterAndIndexNode(); | |
searchNodeWithStrategy = startSearchNode(repositoryStrategy); | |
indexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); | |
XContentBuilder mapping = jsonBuilder().startObject().field("dynamic", true).endObject(); | |
assertAcked(indicesAdmin().prepareCreate(indexName).setMapping(mapping).setSettings( | |
Settings.builder() | |
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | |
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) | |
)); | |
ensureGreen(indexName); | |
searchNode = startSearchNode(printingRepositoryStrategy); | |
ensureGreen(); | |
shardId = new ShardId(resolveIndex(indexName), 0); | |
} | |
@After | |
public void teardownTest() { | |
assertAcked(client().admin().indices().prepareDelete(indexName)); | |
indexNode = null; | |
searchNodeWithStrategy = null; | |
searchNode = null; | |
indexName = null; | |
} | |
public void testRetainCommitForReadersAfterShardMovedAway() throws ExecutionException, InterruptedException { | |
logger.info("~~~starting test"); | |
int docsToIndex = 50; | |
var bulkRequest = client().prepareBulk(); | |
for (int i = 0; i < docsToIndex; i++) { | |
bulkRequest.add(new IndexRequest(indexName).source("field", randomUnicodeOfCodepointLengthBetween(1, 25))); | |
} | |
var bulkResponse = bulkRequest.get(); | |
assertNoFailures(bulkResponse); | |
prepareIndex("test").setId("1").setSource(XContentType.JSON, "field1", "value1").get(); | |
prepareIndex("test").setSource(XContentType.JSON, "message", "wanderlust", "field1", 4, "foo", 3, "bar", "turtles").get(); | |
prepareIndex("test").setSource(XContentType.JSON, "field3", "value3", "rutroh", "fifty", "gah", 50).get(); | |
indexDocs(indexName, scaledRandomIntBetween(10, 50)); | |
logger.info("~~~done writing, about to flush/refresh"); | |
flush(indexName); | |
refresh(indexName); | |
repositoryStrategy.setBlockReadsLatch(); | |
assertResponse(prepareSearch().setQuery(QueryBuilders.matchQuery("message", "wanderlust")), response -> { | |
logger.info("~~~response1: " + response); | |
}); | |
logger.info("~~~finished one query, starting the other"); | |
assertResponse(prepareSearch().setQuery(QueryBuilders.matchAllQuery()), response -> { | |
logger.info("~~~response2: " + response); | |
}); | |
logger.info("--> relocate replica shard from: {} to: {}", searchNodeWithStrategy, searchNode); | |
clusterAdmin() | |
.prepareReroute() | |
.add(new MoveAllocationCommand(indexName, 0, searchNodeWithStrategy, searchNode)) | |
.execute() | |
.actionGet() | |
.getState(); | |
ensureGreen(indexName); | |
logger.info("--> relocation finished"); | |
logger.info("~~~done flush/refresh"); | |
repositoryStrategy.releaseBlockReadsLatch(); | |
logger.info("~~~done reading"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment