Skip to content

Commit

Permalink
GEODE-7257: Remove unnecessary uses of log4j-core (apache#4098)
Browse files Browse the repository at this point in the history
Reimplement tests without using log4j-core:
* ManagementRequestLoggingDistributedTest
* GfshParserAutoCompletionIntegrationTest
* GoldenTestCase

Remove log4j-core and log4j-core:tests dependencies from:
* geode-assembly
* geode-junit
* geode-pulse
* geode-serialization
  • Loading branch information
kirklund authored Oct 1, 2019
1 parent 70eaacc commit f452b9b
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 250 deletions.
2 changes: 0 additions & 2 deletions geode-assembly/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ dependencies {
distributedTestCompile('org.springframework:spring-web')
distributedTestCompile(project(':geode-management'))
distributedTestCompile(project(':geode-web-management'))
distributedTestCompile('org.apache.logging.log4j:log4j-core::tests')
distributedTestCompile('org.apache.logging.log4j:log4j-core::test-sources')
distributedTestCompile('com.arakelian:java-jq')

distributedTestRuntime(project(':extensions:geode-modules-session-internal')) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* 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.geode.management.internal.rest;

import static java.nio.charset.Charset.defaultCharset;
import static org.apache.commons.io.FileUtils.readFileToString;
import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
import static org.apache.geode.internal.AvailablePort.SOCKET;
import static org.apache.geode.internal.AvailablePort.getRandomAvailablePort;
import static org.apache.geode.test.dunit.VM.getVM;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.Serializable;
import java.nio.file.Path;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import org.apache.geode.distributed.LocatorLauncher;
import org.apache.geode.distributed.ServerLauncher;
import org.apache.geode.management.api.ClusterManagementResult;
import org.apache.geode.management.api.ClusterManagementService;
import org.apache.geode.management.client.ClusterManagementServiceBuilder;
import org.apache.geode.management.configuration.Region;
import org.apache.geode.management.configuration.RegionType;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.rules.DistributedRule;
import org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder;

@SuppressWarnings("serial")
public class ManagementRequestLoggingDistributedTest implements Serializable {

private static LocatorLauncher locatorLauncher;
private static ServerLauncher serverLauncher;

private VM locatorVM;
private VM serverVM;

private String locatorName;
private String serverName;
private File locatorDir;
private File serverDir;
private int httpPort;
private int locatorPort;

private transient ClusterManagementService service;

@Rule
public DistributedRule distributedRule = new DistributedRule();

@Rule
public SerializableTemporaryFolder temporaryFolder = new SerializableTemporaryFolder();

@Before
public void setUp() throws Exception {
locatorVM = getVM(0);
serverVM = getVM(1);

locatorName = "locator1";
serverName = "server1";
locatorDir = temporaryFolder.newFolder(locatorName);
serverDir = temporaryFolder.newFolder(serverName);
httpPort = getRandomAvailablePort(SOCKET);

locatorPort = locatorVM.invoke(this::startLocator);
serverVM.invoke(this::startServer);

service = ClusterManagementServiceBuilder.buildWithHostAddress()
.setHostAddress("localhost", httpPort)
.build();
}

@After
public void tearDown() {
locatorVM.invoke(() -> {
if (locatorLauncher != null) {
locatorLauncher.stop();
locatorLauncher = null;
}
});

serverVM.invoke(() -> {
if (serverLauncher != null) {
serverLauncher.stop();
serverLauncher = null;
}
});
}

@Test
public void checkRequestsAreLogged() {
Region regionConfig = new Region();
regionConfig.setName("customers");
regionConfig.setType(RegionType.REPLICATE);

ClusterManagementResult result = service.create(regionConfig);

assertThat(result.isSuccessful()).isTrue();

locatorVM.invoke(() -> {
Path logFile = locatorDir.toPath().resolve(locatorName + ".log");
String logContents = readFileToString(logFile.toFile(), defaultCharset());

// Note: the following is kind of fragile. Remove experimental when it goes away.
// Also feel free to change the following to use regex or substrings

assertThat(logContents)
.containsSubsequence(
"Management Request:",
" POST[url=/management/experimental/regions];",
" user=null;",
" payload={\"class\":\"org.apache.geode.management.configuration.Region\",\"group\":null,\"name\":\"customers\",\"type\":\"REPLICATE\",\"keyConstraint\":null,\"valueConstraint\":null,\"diskStoreName\":null,\"redundantCopies\":null,\"expirations\":null,\"uri\":\"/management/experimental/regions/customers\"}")
.containsSubsequence(
"Management Response:",
" Status=201;",
" response={\"statusCode\":\"OK\",\"statusMessage\":\"Successfully updated configuration for cluster.\",\"uri\":\"/management/experimental/regions/customers\",\"memberStatuses\":[{\"memberName\":\"server1\",\"success\":true,\"message\":\"Region successfully created.\"}]}");
});
}

private int startLocator() {
LocatorLauncher.Builder builder = new LocatorLauncher.Builder();
builder.setMemberName(locatorName);
builder.setWorkingDirectory(locatorDir.getAbsolutePath());
builder.setPort(0);
builder.set(HTTP_SERVICE_PORT, String.valueOf(httpPort));

locatorLauncher = builder.build();
locatorLauncher.start();

return locatorLauncher.getPort();
}

private void startServer() {
ServerLauncher.Builder builder = new ServerLauncher.Builder();
builder.setMemberName(serverName);
builder.setWorkingDirectory(serverDir.getAbsolutePath());
builder.setServerPort(0);
builder.set(LOCATORS, "localHost[" + locatorPort + "]");

serverLauncher = builder.build();
serverLauncher.start();
}
}
Loading

0 comments on commit f452b9b

Please sign in to comment.