Skip to content

Commit

Permalink
GEODE-17: make sure commands tests are run in useHttp mode.
Browse files Browse the repository at this point in the history
* added the CommandOverHttpDUnitTest in geode-web
* added GfshCommandsOverHttpSecurityTest in geode-web
* move ConnectCommandWithHttpAndSSLDUnitTest to geode-web
* make sure ConnectCommandWithHttpAndSSLDUnitTest is running with the correct connection method
* updated the trusted.keystore with the supported algorithm
* create a SuiteRunner so that we can run tests in a suite yet have them report to its own xml
  • Loading branch information
jinmeiliao committed May 13, 2016
1 parent 97d6172 commit c79b64f
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
import java.util.Properties;
import java.util.Set;

import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.RegionShortcut;
Expand All @@ -61,6 +57,10 @@
import com.gemstone.gemfire.test.dunit.WaitCriterion;
import com.gemstone.gemfire.test.junit.categories.DistributedTest;

import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.junit.experimental.categories.Category;

@Category(DistributedTest.class)
public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {

Expand Down Expand Up @@ -116,7 +116,7 @@ public final void preTearDownCliCommandTestBase() throws Exception {
public void testStartServerAndExecuteCommands() throws Exception {
final HeadlessGfsh gfsh = new HeadlessGfsh("gfsh2", 300, this.gfshDir);
assertNotNull(gfsh);
shellConnect(jmxHost, jmxPort, httpPort, gfsh);
connect(jmxHost, jmxPort, httpPort, gfsh);

serverNames.addAll(startServers(gfsh, locatorString, 2, "Server", 1));
doCreateCommands();
Expand Down Expand Up @@ -380,7 +380,7 @@ public String description() {
int jmxPort = (Integer)result[2];
int httpPort = (Integer)result[3];

shellConnect(jmxHost, jmxPort, httpPort, gfsh);
connect(jmxHost, jmxPort, httpPort, gfsh);

// Create a cache in VM 1
VM dataMember = getHost(0).getVM(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ShiroPrincipal(Subject subject){

@Override
public String getName() {
return subject.toString();
return subject.getPrincipal().toString();
}

public Subject getSubject(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.gemstone.gemfire.management.internal.cli.result.CommandResult;
import com.gemstone.gemfire.management.internal.cli.shell.Gfsh;
import com.gemstone.gemfire.management.internal.cli.util.CommandStringBuilder;
import com.gemstone.gemfire.management.internal.security.JSONAuthorization;
import com.gemstone.gemfire.test.dunit.Host;
import com.gemstone.gemfire.test.dunit.cache.internal.JUnit4CacheTestCase;

Expand All @@ -57,11 +56,8 @@ public abstract class CliCommandTestBase extends JUnit4CacheTestCase {

private transient HeadlessGfsh shell;

protected boolean useHttpOnConnect = false;
protected boolean enableAuth = false;
protected String jsonAuthorization = "cacheServer.json";
protected String username = "super-user";
protected String password = "1234567";
public static final String USE_HTTP_SYSTEM_PROPERTY = "useHTTP";
private boolean useHttpOnConnect = Boolean.getBoolean(USE_HTTP_SYSTEM_PROPERTY);

private transient int httpPort;
private transient int jmxPort;
Expand Down Expand Up @@ -107,12 +103,12 @@ protected void preTearDownCliCommandTestBase() throws Exception {
@SuppressWarnings("serial")
protected HeadlessGfsh setUpJmxManagerOnVm0ThenConnect(final Properties props) {
setUpJMXManagerOnVM(0, props);
shellConnect();
connect(this.jmxHost, this.jmxPort, this.httpPort, getDefaultShell());
return shell;
}

protected void setUpJMXManagerOnVM(int vm, final Properties props) {
Object[] result = (Object[]) Host.getHost(0).getVM(vm).invoke("setUpJmxManagerOnVm0ThenConnect", () -> {
Object[] result = (Object[]) Host.getHost(0).getVM(vm).invoke("setUpJmxManagerOnVm"+vm, () -> {
final Object[] results = new Object[3];
final Properties localProps = (props != null ? props : new Properties());

Expand All @@ -138,14 +134,6 @@ protected void setUpJMXManagerOnVM(int vm, final Properties props) {
localProps.setProperty(DistributionConfig.JMX_MANAGER_PORT_NAME, String.valueOf(jmxPort));
localProps.setProperty(DistributionConfig.HTTP_SERVICE_PORT_NAME, String.valueOf(httpPort));

if (enableAuth) {
localProps.put(DistributionConfig.SECURITY_CLIENT_AUTHENTICATOR_NAME,
JSONAuthorization.class.getName() + ".create");
localProps.put(DistributionConfig.SECURITY_CLIENT_ACCESSOR_NAME, JSONAuthorization.class.getName() + ".create");

JSONAuthorization.setUpWithJsonFile(jsonAuthorization);
}

getSystem(localProps);
verifyManagementServiceStarted(getCache());

Expand Down Expand Up @@ -214,33 +202,9 @@ private void verifyManagementServiceStopped() {
}
}

/**
* Connect a shell to the JMX server at the given host and port
*
*
* @param host Host of the JMX server
* @param jmxPort Port of the JMX server
* @param shell Shell to connect
*/
protected void shellConnect(final String host, final int jmxPort, final int httpPort, HeadlessGfsh shell) {
assertTrue(host != null);
assertTrue(shell != null);

connect(host, jmxPort, httpPort, shell);
}

protected CommandResult shellConnect(){
return connect(this.jmxHost, this.jmxPort, this.httpPort, getDefaultShell());
}

protected CommandResult connect(final String host, final int jmxPort, final int httpPort, HeadlessGfsh shell){
protected void connect(final String host, final int jmxPort, final int httpPort, HeadlessGfsh shell){
final CommandStringBuilder command = new CommandStringBuilder(CliStrings.CONNECT);

if(enableAuth) {
command.addOption(CliStrings.CONNECT__USERNAME, username);
command.addOption(CliStrings.CONNECT__PASSWORD, password);
}

String endpoint;
if (useHttpOnConnect) {
endpoint = "http://" + host + ":" + httpPort + "/gemfire/v1";
Expand All @@ -261,7 +225,6 @@ protected CommandResult connect(final String host, final int jmxPort, final int

info("Successfully connected to managing node using " + (useHttpOnConnect ? "HTTP" : "JMX"));
assertEquals(true, shell.isConnectedAndReady());
return result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
import java.util.Properties;
import java.util.Set;

import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.distributed.DistributedMember;
Expand All @@ -54,6 +51,9 @@
import com.gemstone.gemfire.test.dunit.WaitCriterion;
import com.gemstone.gemfire.test.junit.categories.DistributedTest;

import org.junit.Test;
import org.junit.experimental.categories.Category;

/**
* DUnit test to test export and import of shared configuration.
*/
Expand Down Expand Up @@ -167,7 +167,7 @@ public String description() {
});

HeadlessGfsh gfsh = getDefaultShell();
shellConnect(locator1JmxHost, locator1JmxPort, locator1HttpPort, gfsh);
connect(locator1JmxHost, locator1JmxPort, locator1HttpPort, gfsh);

// Create a cache in VM 1
VM dataMember = getHost(0).getVM(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@

@Category(IntegrationTest.class)
public class GfshCommandsSecurityTest {
private static int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
private static int jmxPort = ports[0];
private static int httpPort = ports[1];
protected static int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
protected static int jmxPort = ports[0];
protected static int httpPort = ports[1];

private HeadlessGfsh gfsh = null;

Expand All @@ -50,12 +50,13 @@ public class GfshCommandsSecurityTest {
jmxPort, httpPort, "cacheServer.json");

@Rule
public GfshShellConnectionRule gfshConnection = null;
public GfshShellConnectionRule gfshConnection;

public GfshCommandsSecurityTest(){
gfshConnection = new GfshShellConnectionRule(jmxPort, httpPort, false);
}


@Before
public void before(){
gfsh = gfshConnection.getGfsh();
Expand Down
Binary file modified geode-core/src/test/resources/ssl/trusted.keystore
100755 → 100644
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 com.gemstone.gemfire.test.junit.runner;

import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;

/**
* used by SuiteRunner to override the test method name
*/
public class SuiteBlockRunner extends BlockJUnit4ClassRunner {

private Class<?> suiteClass;

/**
* Creates a BlockJUnit4ClassRunner to run {@code klass}
* @param klass
* @throws InitializationError if the test class is malformed.
*/
public SuiteBlockRunner(final Class parentClass, final Class<?> klass) throws InitializationError {
super(klass);
this.suiteClass = parentClass;
}

@Override
protected String testName(FrameworkMethod method) {
return method.getName()+"@"+ suiteClass.getName();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 com.gemstone.gemfire.test.junit.runner;

import java.util.ArrayList;
import java.util.List;

import org.junit.runner.Runner;
import org.junit.runners.Suite;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.RunnerBuilder;

/**
* SuiteRunner is like Junit Suite, it's used in conjunction with <code>SuiteClass({xx.class, yy.class})</code>
* It's different from Suite in two ways:
* 1. it should only contain contain Junit4 test classes
* 2. the test method names inside each test class are appended with the suiteClass name so that the result will show up different
* as when you run these tests alone.
*/
public class SuiteRunner extends Suite {

public SuiteRunner(final Class<?> klass, final RunnerBuilder builder) throws InitializationError {
super(klass, getRunners(klass));
}

private static List<Runner> getRunners(final Class<?> klass) throws InitializationError{
SuiteClasses annotation = klass.getAnnotation(SuiteClasses.class);
if (annotation == null) {
throw new InitializationError(String.format("class '%s' must have a SuiteClasses annotation", klass.getName()));
}
Class<?>[] childClasses = annotation.value();
List<Runner> runners = new ArrayList<>();
for(Class childClass:childClasses){
runners.add(new SuiteBlockRunner(klass, childClass));
}
return runners;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
import java.util.Properties;
import java.util.Set;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.Region;
Expand Down Expand Up @@ -80,6 +76,10 @@
import com.gemstone.gemfire.test.dunit.WaitCriterion;
import com.gemstone.gemfire.test.junit.categories.DistributedTest;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

@Category(DistributedTest.class)
public class ClusterConfigurationDUnitTest extends CliCommandTestBase {

Expand Down Expand Up @@ -663,7 +663,7 @@ public String description() {
int jmxPort = (Integer)result[2];
int httpPort = (Integer)result[3];

shellConnect(jmxHost, jmxPort, httpPort, gfsh);
connect(jmxHost, jmxPort, httpPort, gfsh);

final String dataMemberWorkingDir = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + dataMember;

Expand Down
11 changes: 11 additions & 0 deletions geode-web/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ dependencies {
testCompile project(':geode-junit')
testRuntime project(':geode-common')
testRuntime project(':geode-core')
testCompile files(project(':geode-core').sourceSets.test.output)

testRuntime files(war.destinationDir)
}

//Remove the gradle output directories from the eclipse classpath. These
Expand All @@ -69,6 +72,14 @@ idea.module.iml {
}
}

distributedTest {
dependsOn ':geode-core:webJar', 'war'
}

integrationTest {
dependsOn ':geode-core:webJar', 'war'
}

war {
classpath configurations.runtime
classpath project(':geode-core').webJar.archivePath
Expand Down
Loading

0 comments on commit c79b64f

Please sign in to comment.