Skip to content

Commit

Permalink
Run spotless and exclude checkstyle on server module
Browse files Browse the repository at this point in the history
Signed-off-by: Owais Kazi <owaiskazi19@gmail.com>
  • Loading branch information
owaiskazi19 committed Oct 18, 2021
1 parent 8ea3364 commit 245e436
Show file tree
Hide file tree
Showing 4,085 changed files with 213,345 additions and 128,467 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
9 changes: 3 additions & 6 deletions buildSrc/src/main/resources/checkstyle_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@
<suppress files="modules[/\\]lang-painless[/\\]src[/\\]main[/\\]java[/\\]org[/\\]opensearch[/\\]painless[/\\]antlr[/\\]PainlessLexer\.java" checks="." />
<suppress files="modules[/\\]lang-painless[/\\]src[/\\]main[/\\]java[/\\]org[/\\]opensearch[/\\]painless[/\\]antlr[/\\]PainlessParser(|BaseVisitor|Visitor)\.java" checks="." />

<!-- JNA requires the no-argument constructor on JNAKernel32Library.SizeT to be public-->
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]opensearch[/\\]bootstrap[/\\]JNAKernel32Library.java" checks="RedundantModifier" />

<!-- the constructors on some local classes in these tests must be public-->
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]opensearch[/\\]plugins[/\\]PluginsServiceTests.java" checks="RedundantModifier" />

<!-- Intentionally doesn't have a package declaration to test logging
configuration of classes that aren't in packages. -->
<suppress files="test[/\\]framework[/\\]src[/\\]test[/\\]java[/\\]Dummy.java" checks="PackageDeclaration" />

<!-- Intentionally has long example curl commands to coincide with sibling Painless tests. -->
<suppress files="modules[/\\]lang-painless[/\\]src[/\\]test[/\\]java[/\\]org[/\\]opensearch[/\\]painless[/\\]ContextExampleTests.java" checks="LineLength" />

<!-- Exclude server to run checkstyle -->
<suppress files="server" checks="." />

<!--
Truly temporary suppressions suppression of snippets included in
documentation that are so wide that they scroll.
Expand Down
1 change: 0 additions & 1 deletion gradle/formatting.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def projectPathsToExclude = [
':plugins:transport-nio',
':qa:die-with-dignity',
':rest-api-spec',
':server',
':test:fixtures:azure-fixture',
':test:fixtures:gcs-fixture',
':test:fixtures:hdfs-fixture',
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,16 @@ public class RejectionActionIT extends OpenSearchIntegTestCase {
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put("thread_pool.search.size", 1)
.put("thread_pool.search.queue_size", 1)
.put("thread_pool.write.size", 1)
.put("thread_pool.write.queue_size", 1)
.put("thread_pool.get.size", 1)
.put("thread_pool.get.queue_size", 1)
.build();
.put(super.nodeSettings(nodeOrdinal))
.put("thread_pool.search.size", 1)
.put("thread_pool.search.queue_size", 1)
.put("thread_pool.write.size", 1)
.put("thread_pool.write.queue_size", 1)
.put("thread_pool.get.size", 1)
.put("thread_pool.get.queue_size", 1)
.build();
}


public void testSimulatedSearchRejectionLoad() throws Throwable {
for (int i = 0; i < 10; i++) {
client().prepareIndex("test", "type", Integer.toString(i)).setSource("field", "1").get();
Expand All @@ -78,39 +77,42 @@ public void testSimulatedSearchRejectionLoad() throws Throwable {
final CopyOnWriteArrayList<Object> responses = new CopyOnWriteArrayList<>();
for (int i = 0; i < numberOfAsyncOps; i++) {
client().prepareSearch("test")
.setSearchType(SearchType.QUERY_THEN_FETCH)
.setQuery(QueryBuilders.matchQuery("field", "1"))
.execute(new LatchedActionListener<>(new ActionListener<SearchResponse>() {
@Override
public void onResponse(SearchResponse searchResponse) {
responses.add(searchResponse);
}
.setSearchType(SearchType.QUERY_THEN_FETCH)
.setQuery(QueryBuilders.matchQuery("field", "1"))
.execute(new LatchedActionListener<>(new ActionListener<SearchResponse>() {
@Override
public void onResponse(SearchResponse searchResponse) {
responses.add(searchResponse);
}

@Override
public void onFailure(Exception e) {
responses.add(e);
}
}, latch));
@Override
public void onFailure(Exception e) {
responses.add(e);
}
}, latch));
}
latch.await();


// validate all responses
for (Object response : responses) {
if (response instanceof SearchResponse) {
SearchResponse searchResponse = (SearchResponse) response;
for (ShardSearchFailure failure : searchResponse.getShardFailures()) {
assertThat(failure.reason().toLowerCase(Locale.ENGLISH),
anyOf(containsString("cancelled"), containsString("rejected")));
assertThat(
failure.reason().toLowerCase(Locale.ENGLISH),
anyOf(containsString("cancelled"), containsString("rejected"))
);
}
} else {
Exception t = (Exception) response;
Throwable unwrap = ExceptionsHelper.unwrapCause(t);
if (unwrap instanceof SearchPhaseExecutionException) {
SearchPhaseExecutionException e = (SearchPhaseExecutionException) unwrap;
for (ShardSearchFailure failure : e.shardFailures()) {
assertThat(failure.reason().toLowerCase(Locale.ENGLISH),
anyOf(containsString("cancelled"), containsString("rejected")));
assertThat(
failure.reason().toLowerCase(Locale.ENGLISH),
anyOf(containsString("cancelled"), containsString("rejected"))
);
}
} else if ((unwrap instanceof OpenSearchRejectedExecutionException) == false) {
throw new AssertionError("unexpected failure", (Throwable) response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
return Collections.singletonList(MockTransportService.TestPlugin.class);
}

public void testNodesInfoTimeout(){
public void testNodesInfoTimeout() {
String masterNode = internalCluster().startMasterOnlyNode();
String dataNode = internalCluster().startDataOnlyNode();
String anotherDataNode = internalCluster().startDataOnlyNode();
Expand All @@ -55,20 +55,20 @@ public void testNodesInfoTimeout(){
NodesInfoResponse response = dataNodeClient().admin().cluster().prepareNodesInfo().get();
assertThat(response.getNodes().size(), equalTo(3));

//simulate timeout on bad node.
// simulate timeout on bad node.
simulateTimeoutAtTransport(dataNode, anotherDataNode, NodesInfoAction.NAME);

// One bad data node
response = dataNodeClient().admin().cluster().prepareNodesInfo().get();
ArrayList<String> nodes = new ArrayList<String>();
for(NodeInfo node : response.getNodes()) {
for (NodeInfo node : response.getNodes()) {
nodes.add(node.getNode().getName());
}
assertThat(response.getNodes().size(), equalTo(2));
assertThat(nodes.contains(masterNode), is(true));
}

public void testNodesStatsTimeout(){
public void testNodesStatsTimeout() {
String masterNode = internalCluster().startMasterOnlyNode();
String dataNode = internalCluster().startDataOnlyNode();
String anotherDataNode = internalCluster().startDataOnlyNode();
Expand All @@ -83,14 +83,14 @@ public void testNodesStatsTimeout(){

NodesStatsResponse response = dataNodeClient().admin().cluster().prepareNodesStats().get();
ArrayList<String> nodes = new ArrayList<String>();
for(NodeStats node : response.getNodes()) {
for (NodeStats node : response.getNodes()) {
nodes.add(node.getNode().getName());
}
assertThat(response.getNodes().size(), equalTo(2));
assertThat(nodes.contains(masterNode), is(true));
}

public void testListTasksTimeout(){
public void testListTasksTimeout() {
String masterNode = internalCluster().startMasterOnlyNode();
String dataNode = internalCluster().startDataOnlyNode();
String anotherDataNode = internalCluster().startDataOnlyNode();
Expand All @@ -107,15 +107,22 @@ public void testListTasksTimeout(){
assertNull(response.getPerNodeTasks().get(anotherDataNode));
}

public void testRecoveriesWithTimeout(){
public void testRecoveriesWithTimeout() {
internalCluster().startMasterOnlyNode();
String dataNode = internalCluster().startDataOnlyNode();
String anotherDataNode = internalCluster().startDataOnlyNode();

int numShards = 4;
assertAcked(prepareCreate("test-index", 0, Settings.builder().
put("number_of_shards", numShards).put("routing.allocation.total_shards_per_node", 2).
put("number_of_replicas", 0)));
assertAcked(
prepareCreate(
"test-index",
0,
Settings.builder()
.put("number_of_shards", numShards)
.put("routing.allocation.total_shards_per_node", 2)
.put("number_of_replicas", 0)
)
);
ensureGreen();
final long numDocs = scaledRandomIntBetween(50, 100);
for (int i = 0; i < numDocs; i++) {
Expand All @@ -129,27 +136,34 @@ public void testRecoveriesWithTimeout(){
assertThat(recoveryResponse.getTotalShards(), equalTo(numShards));
assertThat(recoveryResponse.getSuccessfulShards(), equalTo(numShards));

//simulate timeout on bad node.
// simulate timeout on bad node.
simulateTimeoutAtTransport(dataNode, anotherDataNode, RecoveryAction.NAME);

//verify response with bad node.
// verify response with bad node.
recoveryResponse = dataNodeClient().admin().indices().prepareRecoveries().get();
assertThat(recoveryResponse.getTotalShards(), equalTo(numShards));
assertThat(recoveryResponse.getSuccessfulShards(), equalTo(numShards/2));
assertThat(recoveryResponse.getFailedShards(), equalTo(numShards/2));
assertThat(recoveryResponse.getSuccessfulShards(), equalTo(numShards / 2));
assertThat(recoveryResponse.getFailedShards(), equalTo(numShards / 2));
assertThat(recoveryResponse.getShardFailures()[0].reason(), containsString("ReceiveTimeoutTransportException"));
}

public void testStatsWithTimeout(){
public void testStatsWithTimeout() {
internalCluster().startMasterOnlyNode();
String dataNode = internalCluster().startDataOnlyNode();
String anotherDataNode = internalCluster().startDataOnlyNode();

int numShards = 4;
logger.info("--> creating index");
assertAcked(prepareCreate("test-index", 0, Settings.builder().
put("number_of_shards", numShards).put("routing.allocation.total_shards_per_node", 2).
put("number_of_replicas", 0)));
assertAcked(
prepareCreate(
"test-index",
0,
Settings.builder()
.put("number_of_shards", numShards)
.put("routing.allocation.total_shards_per_node", 2)
.put("number_of_replicas", 0)
)
);
ensureGreen();
final long numDocs = scaledRandomIntBetween(50, 100);
for (int i = 0; i < numDocs; i++) {
Expand All @@ -158,7 +172,7 @@ public void testStatsWithTimeout(){
refresh("test-index");
ensureSearchable("test-index");

//happy case
// happy case
IndicesStatsResponse indicesStats = dataNodeClient().admin().indices().prepareStats().setDocs(true).get();
assertThat(indicesStats.getTotalShards(), equalTo(numShards));
assertThat(indicesStats.getSuccessfulShards(), equalTo(numShards));
Expand All @@ -169,24 +183,28 @@ public void testStatsWithTimeout(){
// verify indices state response with bad node.
indicesStats = dataNodeClient().admin().indices().prepareStats().setDocs(true).get();
assertThat(indicesStats.getTotalShards(), equalTo(numShards));
assertThat(indicesStats.getFailedShards(), equalTo(numShards/2));
assertThat(indicesStats.getSuccessfulShards(), equalTo(numShards/2));
assertThat(indicesStats.getFailedShards(), equalTo(numShards / 2));
assertThat(indicesStats.getSuccessfulShards(), equalTo(numShards / 2));
assertThat(indicesStats.getTotal().getDocs().getCount(), lessThan(numDocs));
assertThat(indicesStats.getShardFailures()[0].reason(), containsString("ReceiveTimeoutTransportException"));
}

private void simulateTimeoutAtTransport(String dataNode, String anotherDataNode, String transportActionName) {
MockTransportService mockTransportService = ((MockTransportService) internalCluster().getInstance(TransportService.class,
dataNode));
MockTransportService mockTransportService = ((MockTransportService) internalCluster().getInstance(
TransportService.class,
dataNode
));
StubbableTransport.SendRequestBehavior sendBehaviour = (connection, requestId, action, request, options) -> {
if (action.startsWith(transportActionName)) {
throw new ReceiveTimeoutTransportException(connection.getNode(), action, "simulate timeout");
}
connection.sendRequest(requestId, action, request, options);
};
mockTransportService.addSendBehavior(internalCluster().getInstance(TransportService.class, anotherDataNode), sendBehaviour);
MockTransportService mockTransportServiceAnotherNode = ((MockTransportService) internalCluster().getInstance(TransportService.class,
anotherDataNode));
MockTransportService mockTransportServiceAnotherNode = ((MockTransportService) internalCluster().getInstance(
TransportService.class,
anotherDataNode
));
mockTransportServiceAnotherNode.addSendBehavior(internalCluster().getInstance(TransportService.class, dataNode), sendBehaviour);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void onResponse(NodesHotThreadsResponse nodeHotThreads) {
assertThat(nodesMap.size(), equalTo(cluster().size()));
for (NodeHotThreads ht : nodeHotThreads.getNodes()) {
assertNotNull(ht.getHotThreads());
//logger.info(ht.getHotThreads());
// logger.info(ht.getHotThreads());
}
success = true;
} finally {
Expand All @@ -126,19 +126,24 @@ public void onFailure(Exception e) {
}
});

indexRandom(true,
client().prepareIndex("test", "type1", "1").setSource("field1", "value1"),
client().prepareIndex("test", "type1", "2").setSource("field1", "value2"),
client().prepareIndex("test", "type1", "3").setSource("field1", "value3"));
indexRandom(
true,
client().prepareIndex("test", "type1", "1").setSource("field1", "value1"),
client().prepareIndex("test", "type1", "2").setSource("field1", "value2"),
client().prepareIndex("test", "type1", "3").setSource("field1", "value3")
);
ensureSearchable();
while(latch.getCount() > 0) {
while (latch.getCount() > 0) {
assertHitCount(
client().prepareSearch()
.setQuery(matchAllQuery())
.setPostFilter(boolQuery().must(matchAllQuery()).mustNot(boolQuery()
.must(termQuery("field1", "value1")).must(termQuery("field1", "value2"))))
.get(),
3L);
client().prepareSearch()
.setQuery(matchAllQuery())
.setPostFilter(
boolQuery().must(matchAllQuery())
.mustNot(boolQuery().must(termQuery("field1", "value1")).must(termQuery("field1", "value2")))
)
.get(),
3L
);
}
latch.await();
assertThat(hasErrors.get(), is(false));
Expand All @@ -154,8 +159,9 @@ public void testIgnoreIdleThreads() throws ExecutionException, InterruptedExcept
builder.setThreads(Integer.MAX_VALUE);
NodesHotThreadsResponse response = builder.execute().get();

final Matcher<String> containsCachedTimeThreadRunMethod
= containsString("org.opensearch.threadpool.ThreadPool$CachedTimeThread.run");
final Matcher<String> containsCachedTimeThreadRunMethod = containsString(
"org.opensearch.threadpool.ThreadPool$CachedTimeThread.run"
);

int totSizeAll = 0;
for (NodeHotThreads node : response.getNodesMap().values()) {
Expand Down
Loading

0 comments on commit 245e436

Please sign in to comment.