Skip to content
Permalink
Browse files
IGNITE-13874 Add PMD rules and Idea inspections to Ignite 3 project (#9)
  • Loading branch information
agoncharuk committed Feb 2, 2021
1 parent 77d8fb5 commit de12ca207ddb421b9ff67977b84fba87cfb3204b
Show file tree
Hide file tree
Showing 17 changed files with 3,096 additions and 33 deletions.
@@ -27,5 +27,14 @@
</description>

<rule ref="category/java/errorprone.xml/EmptyFinallyBlock" />
<rule ref="category/java/errorprone.xml/AvoidCatchingNPE" />
<rule ref="category/java/errorprone.xml/BrokenNullCheck" />
<rule ref="category/java/errorprone.xml/EmptySwitchStatements" />
<rule ref="category/java/errorprone.xml/EmptyStatementNotInLoop" />
<rule ref="category/java/errorprone.xml/EmptySynchronizedBlock" />
<rule ref="category/java/errorprone.xml/UselessOperationOnImmutable" />

<rule ref="category/java/bestpractices.xml/UnusedLocalVariable" />
<rule ref="category/java/bestpractices.xml/UnusedPrivateField" />
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod" />
</ruleset>

Large diffs are not rendered by default.

@@ -27,6 +27,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.locks.LockSupport;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.inject.Inject;
@@ -153,7 +154,7 @@ private static boolean waitForStart(
var start = System.currentTimeMillis();

while ((System.currentTimeMillis() - start) < timeout.toMillis()) {
Thread.sleep(LOG_FILE_POLL_INTERVAL.toMillis());
LockSupport.parkNanos(LOG_FILE_POLL_INTERVAL.toNanos());

var content = Files.readString(file);

@@ -218,7 +218,7 @@ private static class StandardModuleView {
* @param standardModuleDefinition Module definition.
* @param installed true if module already installed, false otherwise.
*/
public StandardModuleView(StandardModuleDefinition standardModuleDefinition, boolean installed) {
private StandardModuleView(StandardModuleDefinition standardModuleDefinition, boolean installed) {
this.standardModuleDefinition = standardModuleDefinition;
this.installed = installed;
}
@@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.cli.ui;

import java.io.IOException;
@@ -37,7 +37,6 @@
import org.apache.ignite.cli.builtins.module.StandardModuleDefinition;
import org.apache.ignite.cli.builtins.node.NodeManager;
import org.apache.ignite.cli.spec.IgniteCliSpec;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -485,8 +484,8 @@ void get() throws IOException, InterruptedException {

Assertions.assertEquals(0, exitCode);
verify(httpClient).send(
argThat(r -> r.uri().toString().equals("http://localhost:8081/management/v1/configuration/") &&
r.headers().firstValue("Content-Type").get().equals("application/json")),
argThat(r -> "http://localhost:8081/management/v1/configuration/".equals(r.uri().toString()) &&
"application/json".equals(r.headers().firstValue("Content-Type").get())),
any());
assertEquals("{\n" +
" \"baseline\" : {\n" +
@@ -511,8 +510,8 @@ void getSubtree() throws IOException, InterruptedException {

Assertions.assertEquals(0, exitCode);
verify(httpClient).send(
argThat(r -> r.uri().toString().equals("http://localhost:8081/management/v1/configuration/local.baseline") &&
r.headers().firstValue("Content-Type").get().equals("application/json")),
argThat(r -> "http://localhost:8081/management/v1/configuration/local.baseline".equals(r.uri().toString()) &&
"application/json".equals(r.headers().firstValue("Content-Type").get())),
any());
assertEquals("{\n" +
" \"autoAdjust\" : {\n" +
@@ -537,10 +536,10 @@ void setHocon() throws IOException, InterruptedException {

Assertions.assertEquals(0, exitCode);
verify(httpClient).send(
argThat(r -> r.uri().toString().equals("http://localhost:8081/management/v1/configuration/") &&
r.method().equals("POST") &&
argThat(r -> "http://localhost:8081/management/v1/configuration/".equals(r.uri().toString()) &&
"POST".equals(r.method()) &&
r.bodyPublisher().get().contentLength() == expSentContent.getBytes().length &&
r.headers().firstValue("Content-Type").get().equals("application/json")),
"application/json".equals(r.headers().firstValue("Content-Type").get())),
any());
assertEquals("Configuration was updated successfully.\n\n" +
"Use the ignite config get command to view the updated configuration.\n", out.toString());
@@ -562,10 +561,10 @@ void setJson() throws IOException, InterruptedException {

Assertions.assertEquals(0, exitCode);
verify(httpClient).send(
argThat(r -> r.uri().toString().equals("http://localhost:8081/management/v1/configuration/") &&
r.method().equals("POST") &&
argThat(r -> "http://localhost:8081/management/v1/configuration/".equals(r.uri().toString()) &&
"POST".equals(r.method()) &&
r.bodyPublisher().get().contentLength() == expSentContent.getBytes().length &&
r.headers().firstValue("Content-Type").get().equals("application/json")),
"application/json".equals(r.headers().firstValue("Content-Type").get())),
any());
assertEquals("Configuration was updated successfully.\n\n" +
"Use the ignite config get command to view the updated configuration.\n", out.toString());
@@ -1,9 +1,25 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.cli.ui;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import org.jline.terminal.TerminalBuilder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -504,7 +504,7 @@ private static class ConfigurationFieldTypes {
/** Get method type for public interface. */
private final TypeName interfaceGetMethodType;

public ConfigurationFieldTypes(TypeName getMethodType, TypeName unwrappedType, TypeName viewClassType, TypeName initClassType, TypeName changeClassType, TypeName interfaceGetMethodType) {
private ConfigurationFieldTypes(TypeName getMethodType, TypeName unwrappedType, TypeName viewClassType, TypeName initClassType, TypeName changeClassType, TypeName interfaceGetMethodType) {
this.getMethodType = getMethodType;
this.unwrappedType = unwrappedType;
this.viewClassType = viewClassType;
@@ -22,7 +22,6 @@
import java.util.function.Consumer;
import org.apache.ignite.configuration.ConfigurationRegistry;
import org.apache.ignite.configuration.Configurator;
import org.apache.ignite.configuration.PublicConfigurator;
import org.apache.ignite.configuration.internal.NamedList;
import org.apache.ignite.configuration.storage.ConfigurationStorage;
import org.apache.ignite.configuration.storage.StorageException;
@@ -75,25 +74,17 @@ public void test() {
final LocalConfiguration root = configurator.getRoot();
root.baseline().autoAdjust().enabled().value();

try {
Assertions.assertThrows(ConfigurationValidationException.class, () -> {
configurator.set(Selectors.LOCAL_BASELINE_AUTO_ADJUST_ENABLED, false);
Assertions.fail();
}
catch (ConfigurationValidationException e) {
// No-op.
}

});
configurator.set(Selectors.LOCAL_BASELINE_AUTO_ADJUST, new ChangeAutoAdjust().withEnabled(false).withTimeout(0L));
configurator.getRoot().baseline().nodes().get("node1").autoAdjustEnabled(false);
configurator.getRoot().baseline().autoAdjust().enabled(true);
configurator.getRoot().baseline().nodes().get("node1").autoAdjustEnabled(true);

try {
Assertions.assertThrows(ConfigurationValidationException.class, () -> {
configurator.getRoot().baseline().autoAdjust().enabled(false);
Assertions.fail();
} catch (ConfigurationValidationException e) {}

PublicConfigurator<LocalConfiguration> con = new PublicConfigurator<>(configurator);
});
}

/**
@@ -131,12 +131,12 @@ private static final class SelectorHolder {
MethodHandle selectorFn;

/** Constructor for selector. */
public SelectorHolder(Selector<?, ?, ?, ?, ?> selector) {
private SelectorHolder(Selector<?, ?, ?, ?, ?> selector) {
this.selector = selector;
}

/** Constructor for method handle. */
public SelectorHolder(MethodHandle selectorFn) {
private SelectorHolder(MethodHandle selectorFn) {
this.selectorFn = selectorFn;
}

@@ -17,7 +17,9 @@

package org.apache.ignite.rest;

/** */
/**
* Error result represent a tuple of error type and user-friendly error message.
*/
public class ErrorResult {
/** */
private final String type;
@@ -30,4 +32,18 @@ public ErrorResult(String type, String message) {
this.type = type;
this.message = message;
}

/**
* @return Error type describing the class of the error occurred.
*/
public String type() {
return type;
}

/**
* @return User-friendly error message.
*/
public String message() {
return message;
}
}
@@ -20,6 +20,10 @@
import org.apache.ignite.configuration.annotation.Config;
import org.apache.ignite.configuration.annotation.Value;

/**
* Configuration schema for REST endpoint subtree.
*/
@SuppressWarnings("PMD.UnusedPrivateField")
@Config(value = "rest", root = true)
public class RestConfigurationSchema {
/** */
@@ -57,8 +57,6 @@ public void bootstrap(Reader confReader, ConfigurationStorage storage) {

localConfigurator = configurator;

String key = configurator.getRoot().key();

confRegistry.registerConfigurator(configurator);
}

@@ -22,6 +22,7 @@
import org.apache.ignite.configuration.annotation.Value;

/** */
@SuppressWarnings("PMD.UnusedPrivateField")
@Config(value = "auto_adjust")
public class AutoAdjustConfigurationSchema {
/** */
@@ -21,6 +21,7 @@
import org.apache.ignite.configuration.annotation.ConfigValue;

/** */
@SuppressWarnings("PMD.UnusedPrivateField")
@Config
public class BaselineConfigurationSchema {
/** */
@@ -21,6 +21,7 @@
import org.apache.ignite.configuration.annotation.Value;

/** */
@SuppressWarnings("PMD.UnusedPrivateField")
@Config
public class DataStorageConfigurationSchema {
/** */
@@ -23,6 +23,7 @@
/**
*
*/
@SuppressWarnings("PMD.UnusedPrivateField")
@Config(value = "local", root = true)
public class LocalConfigurationSchema {
/** */

0 comments on commit de12ca2

Please sign in to comment.