Skip to content

Commit e5fbb34

Browse files
matrivmergify[bot]
authored andcommitted
Code cleanup for ES tests
Fix some minor warnings, add missing @test annotation to methods, etc.
1 parent c27a6c8 commit e5fbb34

File tree

64 files changed

+440
-444
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+440
-444
lines changed

server/src/test/java/org/elasticsearch/cluster/metadata/ColumnPositionResolverTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121

2222
package org.elasticsearch.cluster.metadata;
2323

24-
import org.junit.Test;
25-
2624
import static org.assertj.core.api.Assertions.assertThat;
2725

26+
import org.junit.Test;
27+
2828
public class ColumnPositionResolverTest {
2929

3030
@Test

server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDeciderTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
*/
1919
package org.elasticsearch.cluster.routing.allocation.decider;
2020

21+
import static io.crate.testing.Asserts.assertThat;
22+
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
23+
24+
import java.util.List;
25+
import java.util.Map;
26+
2127
import org.elasticsearch.Version;
2228
import org.elasticsearch.cluster.ClusterName;
2329
import org.elasticsearch.cluster.ClusterState;
@@ -35,12 +41,6 @@
3541
import org.elasticsearch.test.gateway.TestGatewayAllocator;
3642
import org.junit.Test;
3743

38-
import java.util.List;
39-
import java.util.Map;
40-
41-
import static io.crate.testing.Asserts.assertThat;
42-
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
43-
4444

4545
public class FilterAllocationDeciderTests extends ESAllocationTestCase {
4646

server/src/test/java/org/elasticsearch/common/settings/SettingsTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
package org.elasticsearch.common.settings;
2323

2424
import static io.crate.testing.Asserts.assertThat;
25-
import static org.assertj.core.api.Assertions.assertThat;
2625
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2726

2827
import java.io.ByteArrayInputStream;

server/src/test/java/org/elasticsearch/discovery/PeerFinderTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class PeerFinderTests extends ESTestCase {
8787
private TransportService transportService;
8888
private Iterable<DiscoveryNode> foundPeersFromNotification;
8989

90-
private static long CONNECTION_TIMEOUT_MILLIS = 30000;
90+
private static final long CONNECTION_TIMEOUT_MILLIS = 30000;
9191

9292
class MockTransportAddressConnector implements TransportAddressConnector {
9393
final Map<TransportAddress, DiscoveryNode> reachableNodes = new HashMap<>();
@@ -210,15 +210,15 @@ public void setup() {
210210
= new ClusterConnectionManager(settings, capturingTransport);
211211
StubbableConnectionManager connectionManager
212212
= new StubbableConnectionManager(innerConnectionManager);
213-
connectionManager.setDefaultNodeConnectedBehavior((cm, discoveryNode) -> {
213+
connectionManager.setDefaultNodeConnectedBehavior((_, discoveryNode) -> {
214214
final boolean isConnected = connectedNodes.contains(discoveryNode);
215215
final boolean isDisconnected = disconnectedNodes.contains(discoveryNode);
216216
assert isConnected != isDisconnected : discoveryNode + ": isConnected=" + isConnected + ", isDisconnected=" + isDisconnected;
217217
return isConnected;
218218
});
219-
connectionManager.setDefaultGetConnectionBehavior((cm, discoveryNode) -> capturingTransport.createConnection(discoveryNode));
219+
connectionManager.setDefaultGetConnectionBehavior((_, discoveryNode) -> capturingTransport.createConnection(discoveryNode));
220220
transportService = new TransportService(settings, capturingTransport, deterministicTaskQueue.getThreadPool(),
221-
boundTransportAddress -> localNode, null, connectionManager);
221+
_ -> localNode, null, connectionManager);
222222

223223
transportService.start();
224224
transportService.acceptIncomingRequests();
@@ -634,7 +634,7 @@ public void testOnlyRequestsPeersOncePerRoundButDoesRetryNextRound() {
634634

635635
peerFinder.handlePeersRequest(new PeersRequest(sourceNode, emptyList()));
636636
runAllRunnableTasks();
637-
respondToRequests(node -> {
637+
respondToRequests(_ -> {
638638
throw new AssertionError("there should have been no further requests");
639639
});
640640

server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.elasticsearch.node.Node;
4848
import org.elasticsearch.test.ESTestCase;
4949
import org.elasticsearch.test.IndexSettingsModule;
50+
import org.junit.Test;
5051

5152
import io.crate.common.collections.Sets;
5253
import io.crate.common.io.IOUtils;
@@ -55,6 +56,7 @@
5556
public class NodeEnvironmentTests extends ESTestCase {
5657
private final IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("foo", Settings.EMPTY);
5758

59+
@Test
5860
public void testNodeLock() throws IOException {
5961
final Settings settings = buildEnvSettings(Settings.EMPTY);
6062
NodeEnvironment env = newNodeEnvironment(settings);
@@ -77,6 +79,7 @@ public void testNodeLock() throws IOException {
7779
assertThat(env.lockedShards()).isEmpty();
7880
}
7981

82+
@Test
8083
public void testSegmentInfosTracing() {
8184
// Defaults to not hooking up std out
8285
assertThat(SegmentInfos.getInfoStream()).isNull();
@@ -97,6 +100,7 @@ public void testSegmentInfosTracing() {
97100
}
98101
}
99102

103+
@Test
100104
public void testShardLock() throws Exception {
101105
final NodeEnvironment env = newNodeEnvironment();
102106

@@ -129,7 +133,7 @@ public void testShardLock() throws Exception {
129133
try {
130134
env.shardLock(new ShardId(index, 0), "6");
131135
fail("shard is locked");
132-
} catch (ShardLockObtainFailedException ex) {
136+
} catch (ShardLockObtainFailedException _) {
133137
// expected
134138
}
135139
IOUtils.close(locks);
@@ -139,6 +143,7 @@ public void testShardLock() throws Exception {
139143
env.close();
140144
}
141145

146+
@Test
142147
public void testAvailableIndexFolders() throws Exception {
143148
final NodeEnvironment env = newNodeEnvironment();
144149
final int numIndices = randomIntBetween(1, 10);
@@ -158,6 +163,7 @@ public void testAvailableIndexFolders() throws Exception {
158163
env.close();
159164
}
160165

166+
@Test
161167
public void testAvailableIndexFoldersWithExclusions() throws Exception {
162168
final NodeEnvironment env = newNodeEnvironment();
163169
final int numIndices = randomIntBetween(1, 10);
@@ -181,6 +187,7 @@ public void testAvailableIndexFoldersWithExclusions() throws Exception {
181187
env.close();
182188
}
183189

190+
@Test
184191
public void testResolveIndexFolders() throws Exception {
185192
final NodeEnvironment env = newNodeEnvironment();
186193
final int numIndices = randomIntBetween(1, 10);
@@ -210,6 +217,7 @@ public void testResolveIndexFolders() throws Exception {
210217
env.close();
211218
}
212219

220+
@Test
213221
public void testDeleteSafe() throws Exception {
214222
final NodeEnvironment env = newNodeEnvironment();
215223
final Index index = new Index("foo", "fooUUID");
@@ -269,7 +277,7 @@ public void onFailure(Exception e) {
269277
@Override
270278
public void doRun() throws Exception {
271279
start.await();
272-
try (ShardLock autoCloses = env.shardLock(new ShardId(index, 0), "2")) {
280+
try (var _ = env.shardLock(new ShardId(index, 0), "2")) {
273281
blockLatch.countDown();
274282
Thread.sleep(randomIntBetween(1, 10));
275283
}
@@ -298,6 +306,7 @@ public void doRun() throws Exception {
298306
env.close();
299307
}
300308

309+
@Test
301310
public void testStressShardLock() throws IOException, InterruptedException {
302311
class Int {
303312
int value = 0;
@@ -329,14 +338,15 @@ public void run() {
329338
for (int i = 0; i < iters; i++) {
330339
int shard = randomIntBetween(0, counts.length - 1);
331340
try {
332-
try (ShardLock autoCloses = env.shardLock(new ShardId("foo", "fooUUID", shard), "1",
333-
scaledRandomIntBetween(0, 10))) {
341+
try (var _ = env.shardLock(new ShardId("foo", "fooUUID", shard),
342+
"1",
343+
scaledRandomIntBetween(0, 10))) {
334344
counts[shard].value++;
335345
countsAtomic[shard].incrementAndGet();
336-
assertThat(1).isEqualTo(flipFlop[shard].incrementAndGet());
337-
assertThat(0).isEqualTo(flipFlop[shard].decrementAndGet());
346+
assertThat(flipFlop[shard].incrementAndGet()).isEqualTo(1);
347+
assertThat(flipFlop[shard].decrementAndGet()).isEqualTo(0);
338348
}
339-
} catch (ShardLockObtainFailedException ex) {
349+
} catch (ShardLockObtainFailedException _) {
340350
// ok
341351
}
342352
}
@@ -360,6 +370,7 @@ public void run() {
360370
env.close();
361371
}
362372

373+
@Test
363374
public void testCustomDataPaths() throws Exception {
364375
String[] dataPaths = tmpPaths();
365376
NodeEnvironment env = newNodeEnvironment(dataPaths, "/tmp", Settings.EMPTY);
@@ -394,6 +405,7 @@ public void testCustomDataPaths() throws Exception {
394405
env.close();
395406
}
396407

408+
@Test
397409
public void testNodeIdNotPersistedAtInitialization() throws IOException {
398410
NodeEnvironment env = newNodeEnvironment(new String[0], Settings.builder()
399411
.put("node.local_storage", false)
@@ -417,6 +429,7 @@ public void testNodeIdNotPersistedAtInitialization() throws IOException {
417429
env.close();
418430
}
419431

432+
@Test
420433
public void testExistingTempFiles() throws IOException {
421434
String[] paths = tmpPaths();
422435
// simulate some previous left over temp files
@@ -452,6 +465,7 @@ public void testExistingTempFiles() throws IOException {
452465
}
453466
}
454467

468+
@Test
455469
public void testEnsureNoShardDataOrIndexMetadata() throws IOException {
456470
Settings settings = buildEnvSettings(Settings.EMPTY);
457471
Index index = new Index("test", "testUUID");
@@ -568,6 +582,7 @@ public NodeEnvironment newNodeEnvironment(Settings settings) throws IOException
568582
return new NodeEnvironment(build, TestEnvironment.newEnvironment(build));
569583
}
570584

585+
@Override
571586
public Settings buildEnvSettings(Settings settings) {
572587
return Settings.builder()
573588
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString())

server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public class NodeRepurposeCommandTests extends ESTestCase {
5959
private static final Index INDEX = new Index("testIndex", "testUUID");
6060
private Settings dataMasterSettings;
6161
private Environment environment;
62-
private Path[] nodePaths;
6362
private Settings dataNoMasterSettings;
6463
private Settings noDataNoMasterSettings;
6564
private Settings noDataMasterSettings;
@@ -69,7 +68,7 @@ public void createNodePaths() throws IOException {
6968
dataMasterSettings = buildEnvSettings(Settings.EMPTY);
7069
environment = TestEnvironment.newEnvironment(dataMasterSettings);
7170
try (NodeEnvironment nodeEnvironment = new NodeEnvironment(dataMasterSettings, environment)) {
72-
nodePaths = nodeEnvironment.nodeDataPaths();
71+
Path[] nodePaths = nodeEnvironment.nodeDataPaths();
7372
final String nodeId = randomAlphaOfLength(10);
7473
try (PersistedClusterStateService.Writer writer = new PersistedClusterStateService(nodePaths, nodeId,
7574
xContentRegistry(),
@@ -94,13 +93,15 @@ public void createNodePaths() throws IOException {
9493
.build();
9594
}
9695

96+
@Test
9797
public void testEarlyExitNoCleanup() throws Exception {
9898
createIndexDataFiles(dataMasterSettings, randomInt(10), randomBoolean());
9999

100100
verifyNoQuestions(dataMasterSettings, s -> assertThat(s).contains(NO_CLEANUP));
101101
verifyNoQuestions(dataNoMasterSettings, s -> assertThat(s).contains(NO_CLEANUP));
102102
}
103103

104+
@Test
104105
public void testNothingToCleanup() throws Exception {
105106
verifyNoQuestions(noDataNoMasterSettings, s -> assertThat(s).contains(NO_DATA_TO_CLEAN_UP_FOUND));
106107
verifyNoQuestions(noDataMasterSettings, s -> assertThat(s).contains(NO_SHARD_DATA_TO_CLEAN_UP_FOUND));
@@ -126,7 +127,7 @@ public void testNothingToCleanup() throws Exception {
126127

127128
@Test
128129
public void testLocked() throws IOException {
129-
try (NodeEnvironment env = new NodeEnvironment(dataMasterSettings, TestEnvironment.newEnvironment(dataMasterSettings))) {
130+
try (var _ = new NodeEnvironment(dataMasterSettings, TestEnvironment.newEnvironment(dataMasterSettings))) {
130131
assertThatThrownBy(() -> verifyNoQuestions(noDataNoMasterSettings, null))
131132
.isExactlyInstanceOf(ElasticsearchException.class)
132133
.hasMessageContaining(NodeRepurposeCommand.FAILED_TO_OBTAIN_NODE_LOCK_MSG);
@@ -163,6 +164,7 @@ public void testCleanupAll() throws Exception {
163164
new NodeEnvironment(noDataNoMasterSettings, environment).close();
164165
}
165166

167+
@Test
166168
public void testCleanupShardData() throws Exception {
167169
int shardCount = randomIntBetween(1, 10);
168170
boolean verbose = randomBoolean();

server/src/test/java/org/elasticsearch/gateway/AsyncShardFetchTests.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.elasticsearch.threadpool.ThreadPool;
4242
import org.junit.After;
4343
import org.junit.Before;
44+
import org.junit.Test;
4445

4546
public class AsyncShardFetchTests extends ESTestCase {
4647
private final DiscoveryNode node1 = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Collections.emptyMap(),
@@ -69,6 +70,7 @@ public void terminate() throws Exception {
6970
terminate(threadPool);
7071
}
7172

73+
@Test
7274
public void testClose() throws Exception {
7375
DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).build();
7476
test.addSimulation(node1.getId(), response1);
@@ -86,11 +88,12 @@ public void testClose() throws Exception {
8688
try {
8789
test.fetchData(nodes, emptySet());
8890
fail("fetch data should fail when closed");
89-
} catch (IllegalStateException e) {
91+
} catch (IllegalStateException _) {
9092
// all is well
9193
}
9294
}
9395

96+
@Test
9497
public void testFullCircleSingleNodeSuccess() throws Exception {
9598
DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).build();
9699
test.addSimulation(node1.getId(), response1);
@@ -110,6 +113,7 @@ public void testFullCircleSingleNodeSuccess() throws Exception {
110113
assertThat(fetchData.getData().get(node1)).isSameAs(response1);
111114
}
112115

116+
@Test
113117
public void testFullCircleSingleNodeFailure() throws Exception {
114118
DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).build();
115119
// add a failed response for node1
@@ -142,6 +146,7 @@ public void testFullCircleSingleNodeFailure() throws Exception {
142146
assertThat(fetchData.getData().get(node1)).isSameAs(response1);
143147
}
144148

149+
@Test
145150
public void testIgnoreResponseFromDifferentRound() throws Exception {
146151
DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).build();
147152
test.addSimulation(node1.getId(), response1);
@@ -166,6 +171,7 @@ public void testIgnoreResponseFromDifferentRound() throws Exception {
166171
assertThat(fetchData.getData().get(node1)).isSameAs(response1);
167172
}
168173

174+
@Test
169175
public void testIgnoreFailureFromDifferentRound() throws Exception {
170176
DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).build();
171177
// add a failed response for node1
@@ -191,6 +197,7 @@ public void testIgnoreFailureFromDifferentRound() throws Exception {
191197
assertThat(fetchData.getData()).hasSize(0);
192198
}
193199

200+
@Test
194201
public void testTwoNodesOnSetup() throws Exception {
195202
DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).add(node2).build();
196203
test.addSimulation(node1.getId(), response1);
@@ -219,6 +226,7 @@ public void testTwoNodesOnSetup() throws Exception {
219226
assertThat(fetchData.getData().get(node2)).isSameAs(response2);
220227
}
221228

229+
@Test
222230
public void testTwoNodesOnSetupAndFailure() throws Exception {
223231
DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).add(node2).build();
224232
test.addSimulation(node1.getId(), response1);
@@ -245,6 +253,7 @@ public void testTwoNodesOnSetupAndFailure() throws Exception {
245253
assertThat(fetchData.getData().get(node1)).isSameAs(response1);
246254
}
247255

256+
@Test
248257
public void testTwoNodesAddedInBetween() throws Exception {
249258
DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).build();
250259
test.addSimulation(node1.getId(), response1);
@@ -275,6 +284,7 @@ public void testTwoNodesAddedInBetween() throws Exception {
275284
assertThat(fetchData.getData().get(node2)).isSameAs(response2);
276285
}
277286

287+
@Test
278288
public void testClearCache() throws Exception {
279289
DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).build();
280290
test.addSimulation(node1.getId(), response1);
@@ -321,6 +331,7 @@ public void testClearCache() throws Exception {
321331
assertThat(fetchData.getData().get(node1)).isSameAs(response1_2);
322332
}
323333

334+
@Test
324335
public void testConcurrentRequestAndClearCache() throws Exception {
325336
DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).build();
326337
test.addSimulation(node1.getId(), response1);
@@ -370,7 +381,7 @@ static class Entry {
370381

371382
private final ThreadPool threadPool;
372383
private final Map<String, Entry> simulations = new ConcurrentHashMap<>();
373-
private AtomicInteger reroute = new AtomicInteger();
384+
private final AtomicInteger reroute = new AtomicInteger();
374385

375386
TestFetch(ThreadPool threadPool) {
376387
super(LogManager.getLogger(TestFetch.class), "test", new ShardId("test", "_na_", 1), "", null);
@@ -431,9 +442,7 @@ public void run() {
431442
}
432443
}
433444

434-
435445
static class Response extends BaseNodeResponse {
436-
437446
Response(DiscoveryNode node) {
438447
super(node);
439448
}

0 commit comments

Comments
 (0)