SGF-335 - Refactor ProcessUtils and fix the GatewayReceiverNamespaceTest class hang in the Bamboo SDG Nightly Build when mocking is disabled.

This commit is contained in:
John Blum
2014-09-26 17:25:44 -07:00
parent fccb737849
commit 2896bc00f3
7 changed files with 299 additions and 97 deletions

View File

@@ -0,0 +1,85 @@
/*
* Copyright 2010-2013 the original author or authors.
*
* Licensed 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.springframework.data.gemfire.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StringUtils;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
/**
* The GatewayReceiverAutoStartNamespaceTest class is a test suite of test cases testing the contract
* and functionality of Gateway Receiver configuration in Spring Data GemFire using the XML namespace (XSD).
* This test class tests the auto start configuration of the GatewayReceiver Gemfire Component in SDG.
*
* @author John Blum
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
* @see org.springframework.test.context.ActiveProfiles
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
* @see com.gemstone.gemfire.cache.wan.GatewayReceiver
* @since 1.5.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = "GatewayReceiverNamespaceTest-context.xml",
initializers = GemfireTestApplicationContextInitializer.class)
@ActiveProfiles("autoStart")
@SuppressWarnings("unused")
public class GatewayReceiverAutoStartNamespaceTest {
@Resource(name = "&Auto")
private GatewayReceiverFactoryBean autoGatewayReceiverFactory;
@Test
public void testAuto() throws Exception {
assertNotNull("The 'Auto' GatewayReceiverFactoryBean was not properly configured and initialized!",
autoGatewayReceiverFactory);
assertTrue(autoGatewayReceiverFactory.isAutoStartup());
GatewayReceiver autoGatewayReceiver = autoGatewayReceiverFactory.getObject();
try {
assertNotNull(autoGatewayReceiver);
assertTrue(StringUtils.isEmpty(autoGatewayReceiver.getBindAddress()));
assertEquals("neo", autoGatewayReceiver.getHost());
assertEquals(15500, autoGatewayReceiver.getStartPort());
assertEquals(25500, autoGatewayReceiver.getEndPort());
assertEquals(10000, autoGatewayReceiver.getMaximumTimeBetweenPings());
assertTrue(autoGatewayReceiver.isRunning());
assertEquals(16384, autoGatewayReceiver.getSocketBufferSize());
}
finally {
autoGatewayReceiver.stop();
}
}
}

View File

@@ -0,0 +1,85 @@
/*
* Copyright 2010-2013 the original author or authors.
*
* Licensed 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.springframework.data.gemfire.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StringUtils;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
/**
* The GatewayReceiverDefaultStartNamespaceTest class is a test suite of test cases testing the contract
* and functionality of Gateway Receiver configuration in Spring Data GemFire using the XML namespace (XSD).
* This test class tests the default start configuration of the GatewayReceiver Gemfire Component in SDG.
*
* @author John Blum
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
* @see org.springframework.test.context.ActiveProfiles
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
* @see com.gemstone.gemfire.cache.wan.GatewayReceiver
* @since 1.5.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = "GatewayReceiverNamespaceTest-context.xml",
initializers = GemfireTestApplicationContextInitializer.class)
@ActiveProfiles("defaultStart")
@SuppressWarnings("unused")
public class GatewayReceiverDefaultStartNamespaceTest {
@Resource(name = "&Default")
private GatewayReceiverFactoryBean defaultGatewayReceiverFactory;
@Test
public void testDefault() throws Exception {
assertNotNull("The 'Default' GatewayReceiverFactoryBean was not properly configured and initialized!",
defaultGatewayReceiverFactory);
assertTrue(defaultGatewayReceiverFactory.isAutoStartup());
GatewayReceiver defaultGatewayReceiver = defaultGatewayReceiverFactory.getObject();
try {
assertNotNull(defaultGatewayReceiver);
assertTrue(StringUtils.isEmpty(defaultGatewayReceiver.getBindAddress()));
assertEquals("skullbox", defaultGatewayReceiver.getHost());
assertEquals(12345, defaultGatewayReceiver.getStartPort());
assertEquals(54321, defaultGatewayReceiver.getEndPort());
assertEquals(5000, defaultGatewayReceiver.getMaximumTimeBetweenPings());
assertTrue(defaultGatewayReceiver.isRunning());
assertEquals(32768, defaultGatewayReceiver.getSocketBufferSize());
}
finally {
defaultGatewayReceiver.stop();
}
}
}

View File

@@ -0,0 +1,79 @@
/*
* Copyright 2010-2013 the original author or authors.
*
* Licensed 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.springframework.data.gemfire.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
/**
* The GatewayReceiverManualStartNamespaceTest class is a test suite of test cases testing the contract
* and functionality of Gateway Receiver configuration in Spring Data GemFire using the XML namespace (XSD).
* This test class tests the manual start configuration of the GatewayReceiver Gemfire Component in SDG.
*
* @author John Blum
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
* @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean
* @see org.springframework.test.context.ActiveProfiles
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
* @see com.gemstone.gemfire.cache.wan.GatewayReceiver
* @since 1.5.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = "GatewayReceiverNamespaceTest-context.xml",
initializers = GemfireTestApplicationContextInitializer.class)
@ActiveProfiles("manualStart")
@SuppressWarnings("unused")
public class GatewayReceiverManualStartNamespaceTest {
@Resource(name = "&Manual")
private GatewayReceiverFactoryBean manualGatewayReceiverFactory;
@Test
public void testManual() throws Exception {
assertNotNull("The 'Manual' GatewayReceiverFactoryBean was not properly configured and initialized!",
manualGatewayReceiverFactory);
assertFalse(manualGatewayReceiverFactory.isAutoStartup());
GatewayReceiver manualGatewayReceiver = manualGatewayReceiverFactory.getObject();
assertNotNull(manualGatewayReceiver);
assertEquals("192.168.0.1", manualGatewayReceiver.getBindAddress());
assertEquals("theOne", manualGatewayReceiver.getHost());
assertEquals(100, manualGatewayReceiver.getStartPort());
assertEquals(900, manualGatewayReceiver.getEndPort());
assertEquals(1000, manualGatewayReceiver.getMaximumTimeBetweenPings());
assertFalse(manualGatewayReceiver.isRunning());
assertEquals(8192, manualGatewayReceiver.getSocketBufferSize());
}
}

View File

@@ -1,86 +0,0 @@
/*
* Copyright 2010-2013 the original author or authors.
*
* Licensed 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.springframework.data.gemfire.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
/**
* The GatewayReceiverNamespaceTest class is a test suite of test cases testing the contract and functionality of
* Gateway Receiver configuration in Spring Data GemFire using the XML namespace and schema (XSD).
*
* @author John Blum
* @see org.junit.Test
* @since 1.5.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class)
@SuppressWarnings("unused")
public class GatewayReceiverNamespaceTest {
@Resource(name = "&Default")
private GatewayReceiverFactoryBean defaultFactoryBean;
@Resource(name = "&Auto")
private GatewayReceiverFactoryBean autoGatewayReceiver;
@Resource(name = "&Manual")
private GatewayReceiverFactoryBean manualGatewayReceiver;
@Test
// TODO test the default value for "manual-start" (true) without explicitly setting the attribute in Spring XML
public void testDefault() throws Exception {
assertNotNull("The 'Default' GatewayReceiverFactoryBean was not properly configured and initialized!", defaultFactoryBean);
assertTrue(defaultFactoryBean.isAutoStartup());
GatewayReceiver defaultGatewayReceiver = defaultFactoryBean.getObject();
assertNotNull(defaultGatewayReceiver);
assertEquals("192.168.0.1", defaultGatewayReceiver.getBindAddress());
assertEquals("skullbox", defaultGatewayReceiver.getHost());
assertEquals(12345, defaultGatewayReceiver.getStartPort());
assertEquals(54321, defaultGatewayReceiver.getEndPort());
assertEquals(5000, defaultGatewayReceiver.getMaximumTimeBetweenPings());
assertEquals(32768, defaultGatewayReceiver.getSocketBufferSize());
}
@Test
public void testAuto() {
assertNotNull("The 'Auto' GatewayReceiverFactoryBean was not properly configured and initialized!", autoGatewayReceiver);
assertTrue(autoGatewayReceiver.isAutoStartup());
}
@Test
public void testManual() {
assertNotNull("The 'Manual' GatewayReceiverFactoryBean was not properly configured and initialized!", manualGatewayReceiver);
assertFalse(manualGatewayReceiver.isAutoStartup());
}
}

View File

@@ -32,16 +32,17 @@ import java.util.Scanner;
import java.util.logging.Logger;
import org.springframework.data.gemfire.test.support.IOUtils;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import com.gemstone.gemfire.management.internal.cli.util.spring.Assert;
/**
* The ProcessUtils class is a utility class for working with process, or specifically instances
* of the Java Process class.
*
* @author John Blum
* @see java.io.File
* @see java.lang.Process
* @see java.lang.management.ManagementFactory
* @see java.lang.management.RuntimeMXBean
* see com.sun.tools.attach.VirtualMachine
* @since 1.5.0
@@ -114,7 +115,7 @@ public abstract class ProcessUtils {
public static int findAndReadPid(final File workingDirectory) {
Assert.isTrue(workingDirectory != null && workingDirectory.isDirectory(), String.format(
"The file system pathname (%1$s) expected to contain a PID file is not a valid directory!",
workingDirectory));
workingDirectory));
File pidFile = findPidFile(workingDirectory);

View File

@@ -12,12 +12,17 @@
*/
package org.springframework.data.gemfire.test;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
import com.gemstone.gemfire.cache.wan.GatewayReceiverFactory;
import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
@@ -26,11 +31,13 @@ import com.gemstone.gemfire.management.internal.cli.util.spring.StringUtils;
/**
* @author David Turanski
* @author John Blum
*
* @see com.gemstone.gemfire.cache.wan.GatewayReceiverFactory
*/
@SuppressWarnings("unused")
public class StubGatewayReceiverFactory implements GatewayReceiverFactory {
private volatile boolean running;
private int endPort;
private int maximumTimeBetweenPings;
private int socketBufferSize;
@@ -125,8 +132,8 @@ public class StubGatewayReceiverFactory implements GatewayReceiverFactory {
}
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.wan.GatewayReceiverFactory#create()
*/
* @see com.gemstone.gemfire.cache.wan.GatewayReceiverFactory#create()
*/
@Override
public GatewayReceiver create() {
GatewayReceiver gatewayReceiver = mock(GatewayReceiver.class);
@@ -139,6 +146,23 @@ public class StubGatewayReceiverFactory implements GatewayReceiverFactory {
when(gatewayReceiver.getMaximumTimeBetweenPings()).thenReturn(this.maximumTimeBetweenPings);
when(gatewayReceiver.getSocketBufferSize()).thenReturn(this.socketBufferSize);
when(gatewayReceiver.getStartPort()).thenReturn(this.startPort);
when(gatewayReceiver.isRunning()).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
return running;
}
});
try {
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
running = true;
return null;
}
}).when(gatewayReceiver).start();
}
catch (IOException e) {
throw new RuntimeException(e);
}
return gatewayReceiver;
}