Skip to content

Commit

Permalink
GEODE-8205: fix locally failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbey37 authored Jun 10, 2020
1 parent ece3a5a commit fe43bc6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 51 deletions.
2 changes: 1 addition & 1 deletion geode-docs/tools_modules/redis_api_for_geode.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ command with gfsh to enable unsupported commands:
redis --enable-unsupported-commands
```
To enable unsupported commands, the Geode server must be started with the Java property `enable-redis-unsupported-commands=true`:
You can also enable unsupported commands when you start the Geode server by setting the Java property `enable-redis-unsupported-commands=true`:
```pre
start server \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public GeodeRedisServerRule() {
protected void before() throws Throwable {
cache = cacheFactory.create();
server = new GeodeRedisServer("localhost", 0);
server.setAllowUnsupportedCommands(true);
server.start();
server.setAllowUnsupportedCommands(true);
}

public GeodeRedisServerRule withProperty(String property, String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,70 +50,74 @@ public class GeodeRedisServerStartupDUnitTest {
@ClassRule
public static GfshCommandRule gfsh = new GfshCommandRule();

@Test
public void startupOnDefaultPort() {
MemberVM server = cluster.startServerVM(0, s -> s
.withProperty(REDIS_PORT, "6379")
.withProperty(REDIS_BIND_ADDRESS, "localhost")
.withProperty(REDIS_ENABLED, "true"));

assertThat(cluster.getRedisPort(server)).isEqualTo(GeodeRedisServer.DEFAULT_REDIS_SERVER_PORT);
}

@Test
public void startupOnRandomPort_whenPortIsZero() {
MemberVM server1 = cluster.startServerVM(0, s -> s
MemberVM server = cluster.startServerVM(0, s -> s
.withProperty(REDIS_PORT, "0")
.withProperty(REDIS_BIND_ADDRESS, "localhost")
.withProperty(REDIS_ENABLED, "true"));

assertThat(cluster.getRedisPort(server1))
assertThat(cluster.getRedisPort(server))
.isNotEqualTo(GeodeRedisServer.DEFAULT_REDIS_SERVER_PORT);

server1.stop();
}

@Test
public void doNotStartup_whenRedisServiceIsNotEnabled() {
MemberVM server1 = cluster.startServerVM(0, s -> s
MemberVM server = cluster.startServerVM(0, s -> s
.withProperty(REDIS_PORT, "0")
.withProperty(REDIS_BIND_ADDRESS, "localhost"));

server1.invoke(() -> {
server.invoke(() -> {
assertThat(ClusterStartupRule.getCache().getService(GeodeRedisService.class))
.as("GeodeRedisService should not exist")
.isNull();
});

server1.stop();
}

@Test
public void whenStartedWithDefaults_unsupportedCommandsAreNotAvailable() {
MemberVM server1 = cluster.startServerVM(0, s -> s
MemberVM server = cluster.startServerVM(0, s -> s
.withProperty(REDIS_PORT, "0")
.withProperty(REDIS_BIND_ADDRESS, "localhost")
.withProperty(REDIS_ENABLED, "true"));

Jedis jedis = new Jedis("localhost", cluster.getRedisPort(server1));
Jedis jedis = new Jedis("localhost", cluster.getRedisPort(server));

assertThatExceptionOfType(JedisDataException.class)
.isThrownBy(() -> jedis.echo("unsupported"))
.withMessageContaining("ECHO is not supported.");

jedis.disconnect();
server1.stop();
}

@Test
public void whenStartedWithDefaults_unsupportedCommandsCanBeEnabledDynamically() {
MemberVM server1 = cluster.startServerVM(0, s -> s
MemberVM server = cluster.startServerVM(0, s -> s
.withProperty(REDIS_PORT, "0")
.withProperty(REDIS_BIND_ADDRESS, "localhost")
.withProperty(REDIS_ENABLED, "true"));

Jedis jedis = new Jedis("localhost", cluster.getRedisPort(server1));
Jedis jedis = new Jedis("localhost", cluster.getRedisPort(server));

assertThatExceptionOfType(JedisDataException.class)
.isThrownBy(() -> jedis.echo("unsupported"))
.withMessageContaining("ECHO is not supported.");

cluster.setEnableUnsupported(server1, true);
cluster.setEnableUnsupported(server, true);

assertThat(jedis.echo("supported")).isEqualTo("supported");

jedis.disconnect();
server1.stop();
}

@Test
Expand Down Expand Up @@ -150,8 +154,6 @@ public void whenStartedWithDefaults_unsupportedCommandsCanBeEnabledDynamicallyWi

jedis.disconnect();
jedis2.disconnect();
server1.stop();
server2.stop();
}

@Test
Expand All @@ -164,7 +166,7 @@ public void whenMixtureOfRedisAndNonRedisServers_unsupportedCommandsCanBeEnabled
.withProperty(REDIS_ENABLED, "true")
.withConnectionToLocator(locator.getPort()));

MemberVM server2 = cluster.startServerVM(2, s -> s
cluster.startServerVM(2, s -> s
.withConnectionToLocator(locator.getPort()));

gfsh.connectAndVerify(locator);
Expand All @@ -174,20 +176,16 @@ public void whenMixtureOfRedisAndNonRedisServers_unsupportedCommandsCanBeEnabled
assertThat(jedis.echo("supported")).isEqualTo("supported");

jedis.disconnect();
server1.stop();
server2.stop();
}

@Test
public void whenNoRedisServers_unsupportedRedisCommandWillError() throws Exception {
MemberVM locator = cluster.startLocatorVM(0);
MemberVM server1 = cluster.startServerVM(1, s -> s
cluster.startServerVM(1, s -> s
.withConnectionToLocator(locator.getPort()));

gfsh.connectAndVerify(locator);
gfsh.executeAndAssertThat("redis --enable-unsupported-commands").statusIsError();

server1.stop();
}

@Test
Expand All @@ -213,8 +211,6 @@ public void whenUnsupportedCommandsEnabledDynamicallyWithGfsh_newGeodeRedisServe
assertThat(jedis.echo("supported")).isEqualTo("supported");

jedis.disconnect();
server1.stop();
server2.stop();
}

@Test
Expand Down Expand Up @@ -244,24 +240,23 @@ public void startupFailsGivenPortAlreadyInUse() throws Exception {
@Test
public void startupWorksGivenAnyLocalAddress() {
String anyLocal = LocalHostUtil.getAnyLocalAddress().getHostAddress();
MemberVM server1 = cluster.startServerVM(0, s -> s
MemberVM server = cluster.startServerVM(0, s -> s
.withProperty(REDIS_PORT, "0")
.withProperty(REDIS_BIND_ADDRESS, anyLocal)
.withProperty(REDIS_ENABLED, "true"));

assertThat(cluster.getRedisPort(server1))
assertThat(cluster.getRedisPort(server))
.isNotEqualTo(GeodeRedisServer.DEFAULT_REDIS_SERVER_PORT);

server1.stop();
}

@Test
public void startupWorksGivenNoBindAddress() {
MemberVM server1 = cluster.startServerVM(0, s -> s
MemberVM server = cluster.startServerVM(0, s -> s
.withProperty(REDIS_PORT, "0")
.withProperty(REDIS_ENABLED, "true"));

assertThat(cluster.getRedisPort(server1))
assertThat(cluster.getRedisPort(server))
.isNotEqualTo(GeodeRedisServer.DEFAULT_REDIS_SERVER_PORT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ public class GeodeRedisServer {
public static final String ENABLE_REDIS_UNSUPPORTED_COMMANDS_PARAM =
"enable-redis-unsupported-commands";

/**
* Initialized with system property value but can also
* be explicitly set by tests.
*/
private static volatile boolean ENABLE_REDIS_UNSUPPORTED_COMMANDS =
private final boolean ENABLE_REDIS_UNSUPPORTED_COMMANDS =
Boolean.getBoolean(ENABLE_REDIS_UNSUPPORTED_COMMANDS_PARAM);

/**
Expand Down Expand Up @@ -277,13 +273,9 @@ public GeodeRedisServer(String bindAddress, int port, String logLevel) {
}

public void setAllowUnsupportedCommands(boolean allowUnsupportedCommands) {
if (regionProvider != null) {
Region<String, Object> configRegion = regionProvider.getConfigRegion();
configRegion.put(GeodeRedisServer.ENABLE_REDIS_UNSUPPORTED_COMMANDS_PARAM,
allowUnsupportedCommands);
} else {
ENABLE_REDIS_UNSUPPORTED_COMMANDS = allowUnsupportedCommands;
}
Region<String, Object> configRegion = regionProvider.getConfigRegion();
configRegion.put(GeodeRedisServer.ENABLE_REDIS_UNSUPPORTED_COMMANDS_PARAM,
allowUnsupportedCommands);
if (allowUnsupportedCommands) {
logUnsupportedCommandWarning();
}
Expand All @@ -293,12 +285,8 @@ public void setAllowUnsupportedCommands(boolean allowUnsupportedCommands) {
* Precedence of the internal property overrides the global system property.
*/
public boolean allowUnsupportedCommands() {
if (regionProvider != null) {
return (boolean) regionProvider.getConfigRegion()
.getOrDefault(ENABLE_REDIS_UNSUPPORTED_COMMANDS_PARAM, ENABLE_REDIS_UNSUPPORTED_COMMANDS);
} else {
return ENABLE_REDIS_UNSUPPORTED_COMMANDS;
}
return (boolean) regionProvider.getConfigRegion()
.getOrDefault(ENABLE_REDIS_UNSUPPORTED_COMMANDS_PARAM, ENABLE_REDIS_UNSUPPORTED_COMMANDS);
}

private void logUnsupportedCommandWarning() {
Expand Down

0 comments on commit fe43bc6

Please sign in to comment.