Skip to content

Commit

Permalink
GEODE-7869: Cleanup warnings in geode-assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-at-work committed Mar 16, 2020
1 parent 8e4601e commit feab561
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 118 deletions.
1 change: 1 addition & 0 deletions geode-assembly/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

apply from: "${rootDir}/${scriptDir}/standard-subproject-configuration.gradle"
apply from: "${rootDir}/${scriptDir}/warnings.gradle"


import org.apache.geode.gradle.plugins.DependencyConstraints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.geode.management.internal.cli.commands;

import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Rule;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionContext;

public class RunOutOfMemoryFunction implements Function {
public class RunOutOfMemoryFunction implements Function<Void> {

@Override
public void execute(FunctionContext context) {
public void execute(FunctionContext<Void> context) {
byte[] bytes = new byte[Integer.MAX_VALUE / 2];
byte[] bytes1 = new byte[Integer.MAX_VALUE / 2];
byte[] bytes2 = new byte[Integer.MAX_VALUE / 2];

Region testRegion = context.getCache().getRegion("/testRegion");
Region<String, byte[]> testRegion = context.getCache().getRegion("/testRegion");
testRegion.put("byteArray", bytes);
testRegion.put("byteArray1", bytes1);
testRegion.put("byteArray2", bytes2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ public void testStatusClusterConfigService() {
gfsh.executeAndAssertThat("status cluster-config-service")
.statusIsSuccess()
.tableHasRowCount(2)
.tableHasRowWithValues("Name", "Status", "locator-0", "RUNNING")
.tableHasRowWithValues("Name", "Status", "locator-1", "RUNNING");
.hasTableSection().hasColumn("Name").containsOnly(locator1.getName(), locator2.getName())
.hasColumn("Status").containsOnly("RUNNING", "RUNNING");

locator2.stop();

gfsh.executeAndAssertThat("status cluster-config-service")
.statusIsSuccess()
.tableHasRowCount(1)
.tableHasRowWithValues("Name", "Status", "locator-0", "RUNNING");
.hasTableSection().hasColumn("Name").containsOnly(locator1.getName()).hasColumn("Status")
.containsOnly("RUNNING");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
*/
package org.apache.geode.management.internal.cli.commands;

import static org.apache.geode.management.cli.Result.Status.ERROR;
import static org.apache.geode.management.cli.Result.Status.OK;
import static org.apache.geode.management.internal.i18n.CliStrings.GROUP;
import static org.apache.geode.management.internal.i18n.CliStrings.START_LOCATOR;
import static org.apache.geode.management.internal.i18n.CliStrings.START_LOCATOR__DIR;
Expand Down Expand Up @@ -55,7 +53,6 @@
import org.apache.geode.distributed.ConfigurationProperties;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.lang.ObjectUtils;
import org.apache.geode.management.internal.cli.result.CommandResult;
import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
import org.apache.geode.management.internal.i18n.CliStrings;
import org.apache.geode.test.awaitility.GeodeAwaitility;
Expand All @@ -69,7 +66,7 @@ public class StopLocatorCommandDUnitTest {
private static final String groupName = "locatorGroup";
private static String locatorConnectionString;
private File workingDir;
private static Integer locatorPort, jmxPort, toStopJmxPort;
private static Integer jmxPort;

@Rule
public final TemporaryFolder temporaryFolder = new TemporaryFolder();
Expand Down Expand Up @@ -105,28 +102,28 @@ public static void afterClass() throws Exception {
public void before() throws Exception {
workingDir = temporaryFolder.newFolder();
int[] availablePorts = AvailablePortHelper.getRandomAvailableTCPPorts(2);
locatorPort = availablePorts[0];
toStopJmxPort = availablePorts[1];
int locatorPort = availablePorts[0];
int toStopJmxPort = availablePorts[1];

final String command = new CommandStringBuilder(START_LOCATOR)
.addOption(START_LOCATOR__MEMBER_NAME, memberName)
.addOption(START_LOCATOR__LOCATORS, locatorConnectionString)
.addOption(START_LOCATOR__PORT, locatorPort.toString())
.addOption(START_LOCATOR__PORT, Integer.toString(locatorPort))
.addOption(GROUP, groupName)
.addOption(START_LOCATOR__J,
"-D" + GEMFIRE_PREFIX + "jmx-manager-port=" + toStopJmxPort.toString())
"-D" + GEMFIRE_PREFIX + "jmx-manager-port=" + toStopJmxPort)
.addOption(START_LOCATOR__J,
"-D" + GEMFIRE_PREFIX + "jmx-manager-hostname-for-clients=localhost")
.addOption(START_LOCATOR__DIR, workingDir.getCanonicalPath())
.getCommandString();

gfsh.connectAndVerify(locator);
gfsh.executeCommand(command);
gfsh.executeAndAssertThat(command).statusIsSuccess();
}

@After
public void after() throws IOException {
gfsh.executeCommand("stop locator --dir=" + workingDir.getCanonicalPath());
gfsh.executeAndAssertThat("stop locator --dir=" + workingDir.getCanonicalPath()).hasOutput();
}

@Test
Expand Down Expand Up @@ -180,10 +177,8 @@ public void testWithMemberID() {
}

private void waitForCommandToSucceed(String command) {
GeodeAwaitility.await().untilAsserted(() -> {
CommandResult result = gfsh.executeCommand(command);
assertThat(result.getStatus()).isEqualTo(OK);
});
GeodeAwaitility.await()
.untilAsserted(() -> gfsh.executeAndAssertThat(command).statusIsSuccess());
}

@Test
Expand All @@ -192,9 +187,7 @@ public void testWithDirOnline() throws IOException {
.addOption(STOP_LOCATOR__DIR, workingDir.getCanonicalPath())
.getCommandString();

CommandResult result = gfsh.executeCommand(command);

assertThat(result.getStatus()).isEqualTo(OK);
gfsh.executeAndAssertThat(command).statusIsSuccess();
gfsh.executeAndAssertThat("list members").doesNotContainOutput(memberName);
}

Expand All @@ -208,11 +201,10 @@ public void testWithDirOffline() throws Exception {
.addOption(STOP_LOCATOR__DIR, workingDir.getCanonicalPath())
.getCommandString();

CommandResult result = gfsh.executeCommand(command);
gfsh.executeAndAssertThat(command).statusIsSuccess();

gfsh.connect(locator);

assertThat(result.getStatus()).isEqualTo(OK);
gfsh.executeAndAssertThat("list members").doesNotContainOutput(memberName);
}

Expand All @@ -222,9 +214,7 @@ public void testWithInvalidMemberName() {
.addOption(STOP_LOCATOR__MEMBER, "invalidMemberName")
.getCommandString();

CommandResult result = gfsh.executeCommand(command);

assertThat(result.getStatus()).isEqualTo(ERROR);
gfsh.executeAndAssertThat(command).statusIsError();
gfsh.executeAndAssertThat("list members").containsOutput(memberName);
}

Expand All @@ -234,9 +224,7 @@ public void testWithInvalidMemberID() {
.addOption(STOP_LOCATOR__MEMBER, "42")
.getCommandString();

CommandResult result = gfsh.executeCommand(command);

assertThat(result.getStatus()).isEqualTo(ERROR);
gfsh.executeAndAssertThat(command).statusIsError();
gfsh.executeAndAssertThat("list members").containsOutput(memberName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -34,6 +35,7 @@
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
import org.apache.geode.test.junit.rules.GeodeDevRestClient;
import org.apache.geode.test.junit.rules.MemberStarterRule;
import org.apache.geode.test.junit.rules.RequiresGeodeHome;

public class ClusterManagementLocatorReconnectDunitTest {
Expand All @@ -50,7 +52,7 @@ public class ClusterManagementLocatorReconnectDunitTest {
@Test
public void clusterManagementRestServiceStillWorksAfterLocatorReconnects() throws Exception {
IgnoredException.addIgnoredException("org.apache.geode.ForcedDisconnectException: for testing");
locator = rule.startLocatorVM(0, l -> l.withHttpService());
locator = rule.startLocatorVM(0, MemberStarterRule::withHttpService);
server = rule.startServerVM(1, locator.getPort());
restClient =
new GeodeDevRestClient("/management/v1", "localhost", locator.getHttpPort(),
Expand All @@ -62,7 +64,7 @@ public void clusterManagementRestServiceStillWorksAfterLocatorReconnects() throw

// wait till locator is disconnected and reconnected
await().pollInterval(1, TimeUnit.SECONDS).until(() -> locator.invoke("waitTillRestarted",
() -> ClusterStartupRule.getLocator().isReconnected()));
() -> Objects.requireNonNull(ClusterStartupRule.getLocator()).isReconnected()));

makeRestCallAndVerifyResult("orders");
}
Expand All @@ -85,7 +87,8 @@ private void makeRestCallAndVerifyResult(String regionName) throws Exception {

// make sure region is created
server.invoke(() -> {
org.apache.geode.cache.Region region = ClusterStartupRule.getCache().getRegion(regionName);
org.apache.geode.cache.Region<?, ?> region =
ClusterStartupRule.getCache().getRegion(regionName);
assertThat(region).isNotNull();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.geode.test.compiler.ClassBuilder;
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
import org.apache.geode.test.junit.rules.MemberStarterRule;
import org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder;

public class DeploymentManagementRedployDUnitTest {
Expand Down Expand Up @@ -85,7 +86,7 @@ public void setup() throws Exception {
jarBVersion1 = createJarWithFunctionB(VERSION1);
jarBVersion2 = createJarWithFunctionB(VERSION2);

locator = lsRule.startLocatorVM(0, l -> l.withHttpService());
locator = lsRule.startLocatorVM(0, MemberStarterRule::withHttpService);
server = lsRule.startServerVM(1, locator.getPort());
client = new ClusterManagementServiceBuilder()
.setPort(locator.getHttpPort())
Expand All @@ -94,7 +95,7 @@ public void setup() throws Exception {
}

@Test
public void redeployJarsWithNewVersionsOfFunctions() throws Exception {
public void redeployJarsWithNewVersionsOfFunctions() {
deployment.setFile(jarAVersion1);
assertManagementResult(client.create(deployment)).isSuccessful();
server.invoke(() -> assertThatCanLoad(JAR_NAME_A, FUNCTION_A));
Expand Down Expand Up @@ -123,10 +124,10 @@ public void redeployJarsWithNewVersionsOfFunctions() throws Exception {
}

@Test
public void redeployJarsWithNewVersionsOfFunctionsAndMultipleLocators() throws Exception {
public void redeployJarsWithNewVersionsOfFunctionsAndMultipleLocators() {
Properties props = new Properties();
props.setProperty("locators", "localhost[" + locator.getPort() + "]");
MemberVM locator2 = lsRule.startLocatorVM(2, props);
lsRule.startLocatorVM(2, props);

deployment.setFile(jarAVersion1);
assertManagementResult(client.create(deployment)).isSuccessful();
Expand All @@ -150,7 +151,7 @@ public void redeployJarsWithNewVersionsOfFunctionsAndMultipleLocators() throws E
private static LoopingFunctionExecutor executor;

@Test
public void hotDeployShouldNotResultInAnyFailedFunctionExecutions() throws Exception {
public void hotDeployShouldNotResultInAnyFailedFunctionExecutions() {
deployment.setFile(jarAVersion1);
assertManagementResult(client.create(deployment)).isSuccessful();
server.invoke(() -> assertThatCanLoad(JAR_NAME_A, FUNCTION_A));
Expand Down Expand Up @@ -186,7 +187,7 @@ private File createJarWithFunctionA(String version) throws Exception {
classContents = classContents.replaceAll("FUNCTION_A", FUNCTION_A);
classContents = classContents.replaceAll("VERSION", version);

File jar = new File(temporaryFolder.newFolder(JAR_NAME_A + version), this.JAR_NAME_A);
File jar = new File(temporaryFolder.newFolder(JAR_NAME_A + version), JAR_NAME_A);
ClassBuilder functionClassBuilder = new ClassBuilder();
functionClassBuilder.writeJarFromContent(FUNCTION_A, classContents, jar);

Expand All @@ -203,18 +204,21 @@ private File createJarWithFunctionB(String version) throws Exception {
classContents = classContents.replaceAll("FUNCTION_B", FUNCTION_B);
classContents = classContents.replaceAll("VERSION", version);

File jar = new File(temporaryFolder.newFolder(JAR_NAME_B + version), this.JAR_NAME_B);
File jar = new File(temporaryFolder.newFolder(JAR_NAME_B + version), JAR_NAME_B);
ClassBuilder functionClassBuilder = new ClassBuilder();
functionClassBuilder.writeJarFromContent("jddunit/function/" + FUNCTION_B, classContents, jar);

return jar;
}

private static void assertThatFunctionHasVersion(String functionId, String version) {
@SuppressWarnings("deprecation")
GemFireCacheImpl gemFireCache = GemFireCacheImpl.getInstance();
DistributedSystem distributedSystem = gemFireCache.getDistributedSystem();
Execution execution = FunctionService.onMember(distributedSystem.getDistributedMember());
List<String> result = (List<String>) execution.execute(functionId).getResult();
@SuppressWarnings("unchecked")
Execution<Void, String, List<String>> execution =
FunctionService.onMember(distributedSystem.getDistributedMember());
List<String> result = execution.execute(functionId).getResult();
assertThat(result.get(0)).isEqualTo(version);
}

Expand All @@ -233,6 +237,7 @@ private static class LoopingFunctionExecutor implements Serializable {
public void startExecuting(String functionId) {
ExecutorService EXECUTOR_SERVICE = Executors.newSingleThreadExecutor();
EXECUTOR_SERVICE.submit(() -> {
@SuppressWarnings("deprecation")
GemFireCacheImpl gemFireCache = GemFireCacheImpl.getInstance();
DistributedSystem distributedSystem = gemFireCache.getDistributedSystem();

Expand Down
Loading

0 comments on commit feab561

Please sign in to comment.