Skip to content

Commit

Permalink
GEODE-7869: Cleanup warnings in geode-tcp-server
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-at-work committed Mar 16, 2020
1 parent 23701b2 commit 028777b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 36 deletions.
1 change: 1 addition & 0 deletions geode-tcp-server/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: "${project.projectDir}/../gradle/publish-java.gradle"
apply from: "${rootDir}/${scriptDir}/warnings.gradle"

dependencies {
api(platform(project(':boms:geode-all-bom')))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ private static TestVersion getOldProductVersion() {
return olderVersions.get(olderVersions.size() - 1);
}

@SuppressWarnings("unused")
private enum VersionConfiguration {
OLD_CURRENT(oldProductVersion, currentProductVersion),
CURRENT_OLD(currentProductVersion, oldProductVersion);
Expand Down Expand Up @@ -154,21 +155,26 @@ public void testAllMessageTypes() {
clientVM.invoke("issue version request",
createRequestResponseFunction(locatorPort, VersionRequest.class.getName(),
VersionResponse.class.getName()));
clientVM.invoke("issue info request",
createRequestResponseFunction(locatorPort, InfoRequest.class.getName(),
InfoResponse.class.getName()));
testDeprecatedMessageTypes(clientVM, locatorPort);
clientVM.invoke("issue shutdown request",
createRequestResponseFunction(locatorPort, ShutdownRequest.class.getName(),
ShutdownResponse.class.getName()));
locatorVM.invoke("wait for locator to stop", () -> {
Locator locator = Locator.getLocator();
if (locator != null) {
((InternalLocator) locator).stop(false, false, false);
GeodeAwaitility.await().until(() -> ((InternalLocator) locator).isStopped());
GeodeAwaitility.await().until(((InternalLocator) locator)::isStopped);
}
});
}

@SuppressWarnings("deprecation")
private void testDeprecatedMessageTypes(VM clientVM, int locatorPort) {
clientVM.invoke("issue info request",
createRequestResponseFunction(locatorPort, InfoRequest.class.getName(),
InfoResponse.class.getName()));
}

private SerializableRunnableIF createRequestResponseFunction(
final int locatorPort,
final String requestClassName,
Expand All @@ -186,17 +192,19 @@ private SerializableRunnableIF createRequestResponseFunction(
tcpClient = getLegacyTcpClient();
}

@SuppressWarnings("deprecation")
final InetAddress localHost = SocketCreator.getLocalHost();
Object response;
try {
Method requestToServer =
TcpClient.class.getMethod("requestToServer", InetAddress.class, int.class, Object.class,
int.class);
response = requestToServer.invoke(tcpClient, SocketCreator.getLocalHost(), locatorPort,
response = requestToServer.invoke(tcpClient, localHost, locatorPort,
requestMessage, 1000);
} catch (NoSuchMethodException e) {
response = tcpClient
.requestToServer(
new HostAndPort(SocketCreator.getLocalHost().getHostAddress(), locatorPort),
new HostAndPort(localHost.getHostAddress(), locatorPort),
requestMessage, 1000);
}

Expand Down Expand Up @@ -255,7 +263,9 @@ public Properties getDistributedSystemProperties() {
Properties properties = new Properties();
properties.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
properties.setProperty(USE_CLUSTER_CONFIGURATION, "false");
properties.setProperty(NAME, "vm" + VM.getCurrentVMNum());
@SuppressWarnings("deprecation")
final int currentVMNum = VM.getCurrentVMNum();
properties.setProperty(NAME, "vm" + currentVMNum);
return properties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
*
* @deprecated this was created for the deprecated Admin API
*/
@Deprecated
public class InfoRequest implements BasicSerializable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void stop(HostAndPort addr) throws java.net.ConnectException {
*
* @deprecated this was created for the deprecated Admin API
*/
@Deprecated
public String[] getInfo(HostAndPort addr) {
try {
InfoRequest request = new InfoRequest();
Expand Down Expand Up @@ -307,7 +308,7 @@ private Short getServerVersion(HostAndPort addr, int timeout)
synchronized (serverVersions) {
serverVersions.put(addr, Version.GFE_57.ordinal());
}
return Short.valueOf(Version.GFE_57.ordinal());
return Version.GFE_57.ordinal();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import org.apache.geode.internal.serialization.BasicSerializable;
import org.apache.geode.internal.serialization.DSFIDSerializer;
Expand Down Expand Up @@ -87,13 +85,15 @@ public void setup() {
}

@Test
public void testConnectToUnknownHost() throws Exception {
public void testConnectToUnknownHost() {
final TcpClient tcpClient = createTcpClient();
@SuppressWarnings("deprecation")
InfoRequest testInfoRequest = new InfoRequest();
assertThatThrownBy(() -> tcpClient.requestToServer(new HostAndPort("unknown host name", port),
testInfoRequest, TIMEOUT)).isInstanceOf(UnknownHostException.class);
}

@SuppressWarnings("deprecation")
@Test
public void testClientGetInfo() throws Exception {
TcpHandler handler = new InfoRequestHandler();
Expand Down Expand Up @@ -131,22 +131,16 @@ public void testConcurrency() throws Exception {
final TcpClient tcpClient = createTcpClient();

final AtomicBoolean done = new AtomicBoolean();
Thread delayedThread = new Thread() {
@Override
public void run() {
Boolean delay = Boolean.valueOf(true);
try {
tcpClient.requestToServer(new HostAndPort(localhost.getHostAddress(), port),
new TestObject(1),
TIMEOUT);
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
done.set(true);
Thread delayedThread = new Thread(() -> {
try {
tcpClient.requestToServer(new HostAndPort(localhost.getHostAddress(), port),
new TestObject(1),
TIMEOUT);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
};
done.set(true);
});
delayedThread.start();
try {
Thread.sleep(500);
Expand All @@ -161,7 +155,7 @@ public void run() {
} finally {
latch.countDown();
delayedThread.join(TIMEOUT);
assertTrue(!delayedThread.isAlive()); // GemStoneAddition
assertFalse(delayedThread.isAlive()); // GemStoneAddition
stopServer(tcpClient);
}
}
Expand All @@ -183,12 +177,8 @@ public void testNewConnectionsAcceptedAfterSocketException() throws IOException,
.isInstanceOf(EOFException.class);

// Change the mock handler behavior to echo the request back
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArgument(0);
}
}).when(mockTcpHandler).processRequest(any(Object.class));
doAnswer(invocation -> invocation.getArgument(0)).when(mockTcpHandler)
.processRequest(any(Object.class));

// Perform another request and validate that it was served successfully
TestObject test = new TestObject();
Expand Down Expand Up @@ -245,7 +235,7 @@ public DelayHandler(CountDownLatch latch) {
public void init(TcpServer tcpServer) {}

@Override
public Object processRequest(Object request) throws IOException {
public Object processRequest(Object request) {
TestObject delay = (TestObject) request;
if (delay.id > 0) {
try {
Expand All @@ -268,11 +258,12 @@ public void endResponse(Object request, long startTime) {}
}


public class InfoRequestHandler implements TcpHandler {
public static class InfoRequestHandler implements TcpHandler {
public InfoRequestHandler() {}

@SuppressWarnings("deprecation")
@Override
public Object processRequest(final Object request) throws IOException {
public Object processRequest(final Object request) {
String[] info = new String[2];
info[0] = System.getProperty("user.dir");
info[1] = System.getProperty("java.version");
Expand Down

0 comments on commit 028777b

Please sign in to comment.