Permalink
Browse files

Added the capability to test based on different ports

Memcached can start on different ports and the tests can be configured to
run correctly than using the default 11211
Fixed checkstyle errors as well.

Change-Id: Ie2a589dc5040d465eb74bb7918f866165109d011
Reviewed-on: http://review.couchbase.org/12127
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
  • Loading branch information...
1 parent 2d78bce commit 36e4014c208e96a6957adaaf7efc92968ddff289 Mike Wiederhold committed with mikewied Jan 8, 2012
View
@@ -43,6 +43,11 @@ This argument is used to set the ipv6 address of your testing server.
By default it is set to ::1. If an ipv6 address is specified then an
ipv4 address must be specified otherwise there may be test failures.
+ -Dserver.port_number=port_number_of_memcached
+
+This argument is used when memcahched is started on a port other than
+11211
+
-Dtest.type=ci
This argument is used for CI testing where certain unit tests might
View
@@ -112,6 +112,7 @@
<property name="server.address_v4" value="127.0.0.1"/>
<property name="server.address_v6" value="::1"/>
<property name="server.type" value="memcached"/>
+ <property name="server.port_number" value="11211"/>
<!--this is the naming policy for artifacts we want pulled down-->
<property name="ivy.artifact.retrieve.pattern"
@@ -236,6 +237,7 @@
description="Run Spymemcached unit tests">
<echo>IPV4 address ${server.address_v4}</echo>
<echo>IPV6 address ${server.address_v6}</echo>
+ <echo>Port Number ${server.port_number}</echo>
<delete dir="${junit.dir}"/>
<mkdir dir="${junit.dir}/data"/>
<junit fork="yes" timeout="60000" failureproperty="junit.failure">
@@ -248,6 +250,7 @@
<jvmarg value="-ea" />
<sysproperty key="server.address_v4" value="${server.address_v4}"/>
<sysproperty key="server.address_v6" value="${server.address_v6}"/>
+ <sysproperty key="server.port_number" value="${server.port_number}"/>
<sysproperty key="server.type" value="${server.type}"/>
<sysproperty key="test.type" value="${test.type}"/>
<formatter type="plain" usefile="false" />
@@ -61,6 +61,7 @@ public void initialize() {
@Override
protected String getExpectedVersionSource() {
- return String.valueOf(new InetSocketAddress(TestConfig.IPV4_ADDR, 11211));
+ return String.valueOf(new InetSocketAddress(TestConfig.IPV4_ADDR,
+ TestConfig.PORT_NUMBER));
}
}
@@ -32,15 +32,18 @@
@Override
protected void initClient(ConnectionFactory cf) throws Exception {
- client = new MemcachedClient(cf, AddrUtil.getAddresses(TestConfig.IPV6_ADDR
- + ":11211"));
+ client = new MemcachedClient(cf,
+ AddrUtil.getAddresses(TestConfig.IPV6_ADDR
+ + ":" + TestConfig.PORT_NUMBER));
}
@Override
protected String getExpectedVersionSource() {
if (TestConfig.defaultToIPV4()) {
- return String.valueOf(new InetSocketAddress(TestConfig.IPV4_ADDR, 11211));
+ return String.valueOf(new InetSocketAddress(TestConfig.IPV4_ADDR,
+ TestConfig.PORT_NUMBER));
}
- return String.valueOf(new InetSocketAddress(TestConfig.IPV6_ADDR, 11211));
+ return String.valueOf(new InetSocketAddress(TestConfig.IPV6_ADDR,
+ TestConfig.PORT_NUMBER));
}
}
@@ -48,7 +48,8 @@ public FailureMode getFailureMode() {
@Override
protected String getExpectedVersionSource() {
- return String.valueOf(new InetSocketAddress(TestConfig.IPV4_ADDR, 11211));
+ return String.valueOf(new InetSocketAddress(TestConfig.IPV4_ADDR,
+ TestConfig.PORT_NUMBER));
}
@Override
@@ -33,14 +33,16 @@
@Override
protected void initClient(ConnectionFactory cf) throws Exception {
client = new MemcachedClient(cf, AddrUtil.getAddresses(TestConfig.IPV6_ADDR
- + ":11211"));
+ + ":" + TestConfig.PORT_NUMBER));
}
@Override
protected String getExpectedVersionSource() {
if (TestConfig.defaultToIPV4()) {
- return String.valueOf(new InetSocketAddress(TestConfig.IPV4_ADDR, 11211));
+ return String.valueOf(new InetSocketAddress(TestConfig.IPV4_ADDR,
+ TestConfig.PORT_NUMBER));
}
- return String.valueOf(new InetSocketAddress(TestConfig.IPV6_ADDR, 11211));
+ return String.valueOf(new InetSocketAddress(TestConfig.IPV6_ADDR,
+ TestConfig.PORT_NUMBER));
}
}
@@ -37,14 +37,15 @@
@Override
protected void setUp() throws Exception {
- serverList = TestConfig.IPV4_ADDR + ":11211 " + TestConfig.IPV4_ADDR
+ serverList = TestConfig.IPV4_ADDR + ":" + TestConfig.PORT_NUMBER
+ + " " + TestConfig.IPV4_ADDR
+ ":11311";
super.setUp();
}
@Override
protected void tearDown() throws Exception {
- serverList = TestConfig.IPV4_ADDR + ":11211";
+ serverList = TestConfig.IPV4_ADDR + ":" + TestConfig.PORT_NUMBER;
super.tearDown();
}
@@ -55,7 +55,7 @@ public FailureMode getFailureMode() {
protected void initClient(ConnectionFactory cf) throws Exception {
client = new MemcachedClient(cf, AddrUtil.getAddresses(TestConfig.IPV4_ADDR
- + ":11211"));
+ + ":" + TestConfig.PORT_NUMBER));
}
protected Collection<String> stringify(Collection<?> c) {
@@ -89,7 +89,8 @@ public void testDefaults() throws Exception {
SocketChannel sc = SocketChannel.open();
try {
assertTrue(f.createMemcachedNode(
- InetSocketAddress.createUnresolved("localhost", 11211), sc, 1)
+ InetSocketAddress.createUnresolved("localhost",
+ TestConfig.PORT_NUMBER), sc, 1)
instanceof AsciiMemcachedNodeImpl);
} finally {
sc.close();
@@ -153,14 +154,16 @@ public void connectionEstablished(SocketAddress sa, int reconnectCount) {
assertSame(anAuthDescriptor, f.getAuthDescriptor());
MemcachedNode n = new MockMemcachedNode(
- InetSocketAddress.createUnresolved("localhost", 11211));
+ InetSocketAddress.createUnresolved("localhost",
+ TestConfig.PORT_NUMBER));
assertTrue(f.createLocator(Collections.singletonList(n))
instanceof KetamaNodeLocator);
SocketChannel sc = SocketChannel.open();
try {
assertTrue(f.createMemcachedNode(
- InetSocketAddress.createUnresolved("localhost", 11211), sc, 1)
+ InetSocketAddress.createUnresolved("localhost",
+ TestConfig.PORT_NUMBER), sc, 1)
instanceof BinaryMemcachedNodeImpl);
} finally {
sc.close();
@@ -110,7 +110,7 @@ private void runThisManyNodes(final int totalNodes) {
int second = (int) (((now / 250) % 250) + 3);
- String port = ":11211 ";
+ String port = ":" + TestConfig.PORT_NUMBER + " ";
int last = (int) ((now % 100) + 3);
StringBuffer prefix = new StringBuffer();
@@ -41,7 +41,8 @@ public static void main(String[] args) throws Exception {
// we're going to add.
MemcachedClient client =
new MemcachedClient(new DefaultConnectionFactory(350000, 32768),
- AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":11211"));
+ AddrUtil.getAddresses(TestConfig.IPV4_ADDR
+ + ":" + TestConfig.PORT_NUMBER));
long start = System.currentTimeMillis();
byte[] toStore = new byte[26];
Arrays.fill(toStore, (byte) 'a');
@@ -60,7 +60,7 @@ protected void tearDown() throws Exception {
private void assertWorking() throws Exception {
Map<SocketAddress, String> versions = client.getVersions();
- assertEquals("/" + TestConfig.IPV4_ADDR + ":11211",
+ assertEquals("/" + TestConfig.IPV4_ADDR + ":" + TestConfig.PORT_NUMBER,
versions.keySet().iterator().next().toString());
}
@@ -72,7 +72,8 @@ private void assertArgRequired(IllegalArgumentException e) {
public void testVarargConstructor() throws Exception {
client =
new MemcachedClient(new InetSocketAddress(
- InetAddress.getByName(TestConfig.IPV4_ADDR), 11211));
+ InetAddress.getByName(TestConfig.IPV4_ADDR),
+ TestConfig.PORT_NUMBER));
assertWorking();
}
@@ -108,7 +109,7 @@ public void testNullFactoryConstructor() throws Exception {
try {
client =
new MemcachedClient(null, AddrUtil.getAddresses(TestConfig.IPV4_ADDR
- + ":11211"));
+ + ":" + TestConfig.PORT_NUMBER));
fail("Expected null pointer exception, got " + client);
} catch (NullPointerException e) {
assertEquals("Connection factory required", e.getMessage());
@@ -122,7 +123,8 @@ public void testNegativeTimeout() throws Exception {
public long getOperationTimeout() {
return -1;
}
- }, AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":11211"));
+ }, AddrUtil.getAddresses(TestConfig.IPV4_ADDR
+ +":" + TestConfig.PORT_NUMBER));
fail("Expected null pointer exception, got " + client);
} catch (IllegalArgumentException e) {
assertEquals("Operation timeout must be positive.", e.getMessage());
@@ -136,7 +138,8 @@ public void testZeroTimeout() throws Exception {
public long getOperationTimeout() {
return 0;
}
- }, AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":11211"));
+ }, AddrUtil.getAddresses(TestConfig.IPV4_ADDR
+ + ":" + TestConfig.PORT_NUMBER));
fail("Expected null pointer exception, got " + client);
} catch (IllegalArgumentException e) {
assertEquals("Operation timeout must be positive.", e.getMessage());
@@ -150,7 +153,8 @@ public void testConnFactoryWithoutOpFactory() throws Exception {
public OperationFactory getOperationFactory() {
return null;
}
- }, AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":11211"));
+ }, AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":"
+ + TestConfig.PORT_NUMBER));
} catch (AssertionError e) {
assertEquals("Connection factory failed to make op factory",
e.getMessage());
@@ -165,7 +169,8 @@ public MemcachedConnection createConnection(
List<InetSocketAddress> addrs) throws IOException {
return null;
}
- }, AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":11211"));
+ }, AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":"
+ + TestConfig.PORT_NUMBER));
} catch (AssertionError e) {
assertEquals("Connection factory failed to make a connection",
e.getMessage());
@@ -175,7 +180,7 @@ public MemcachedConnection createConnection(
public void testArraymodNodeLocatorAccessor() throws Exception {
client =
new MemcachedClient(AddrUtil.getAddresses(TestConfig.IPV4_ADDR
- + ":11211"));
+ + ":" + TestConfig.PORT_NUMBER));
assertTrue(client.getNodeLocator() instanceof ArrayModNodeLocator);
assertTrue(client.getNodeLocator().getPrimary("x")
instanceof MemcachedNodeROImpl);
@@ -184,7 +189,8 @@ public void testArraymodNodeLocatorAccessor() throws Exception {
public void testKetamaNodeLocatorAccessor() throws Exception {
client =
new MemcachedClient(new KetamaConnectionFactory(),
- AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":11211"));
+ AddrUtil.getAddresses(TestConfig.IPV4_ADDR
+ + ":" + TestConfig.PORT_NUMBER));
assertTrue(client.getNodeLocator() instanceof KetamaNodeLocator);
assertTrue(client.getNodeLocator().getPrimary("x")
instanceof MemcachedNodeROImpl);
@@ -40,7 +40,7 @@
public class MemcachedNodeROImplTest extends MockObjectTestCase {
public void testReadOnliness() throws Exception {
- SocketAddress sa = new InetSocketAddress(11211);
+ SocketAddress sa = new InetSocketAddress(TestConfig.PORT_NUMBER);
Mock m = mock(MemcachedNode.class, "node");
MemcachedNodeROImpl node =
new MemcachedNodeROImpl((MemcachedNode) m.proxy());
@@ -40,13 +40,14 @@
@Override
protected void setUp() throws Exception {
serverList =
- TestConfig.IPV4_ADDR + ":11211 " + TestConfig.IPV4_ADDR + ":11311";
+ TestConfig.IPV4_ADDR + ":" + TestConfig.PORT_NUMBER + " "
+ + TestConfig.IPV4_ADDR + ":11311";
super.setUp();
}
@Override
protected void tearDown() throws Exception {
- serverList = TestConfig.IPV4_ADDR + ":11211";
+ serverList = TestConfig.IPV4_ADDR + ":" + TestConfig.PORT_NUMBER;
super.tearDown();
}
@@ -30,6 +30,7 @@
public static final String IPV6_PROP = "server.address_v6";
public static final String TYPE_PROP = "server.type";
public static final String TEST_PROP = "test.type";
+ public static final String PORT_PROP = "server.port_number";
public static final String TYPE_MEMCACHED = "memcached";
public static final String TYPE_MEMBASE = "membase";
public static final String TYPE_COUCHBASE = "couchbase";
@@ -39,6 +40,8 @@
public static final String IPV4_ADDR = System.getProperty(IPV4_PROP,
"127.0.0.1");
public static final String IPV6_ADDR = resolveIpv6Addr();
+ public static final int PORT_NUMBER =
+ Integer.parseInt(System.getProperty(PORT_PROP, "11211"));
public static final String TYPE = System.getProperty(TYPE_PROP,
TYPE_MEMCACHED).toLowerCase();
public static final String TEST_TYPE = System.getProperty(TEST_PROP,
@@ -53,7 +53,8 @@ public long getOperationTimeout() {
public FailureMode getFailureMode() {
return FailureMode.Retry;
}
- }, AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":11211"));
+ }, AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":"
+ + TestConfig.PORT_NUMBER));
}
public void testTimeoutDontwrite() {
@@ -41,9 +41,10 @@
public class CheckedOperationTimeoutExceptionTest extends TestCase {
public void testSingleOperation() {
- Operation op = buildOp(11211);
+ Operation op = buildOp(TestConfig.PORT_NUMBER);
assertEquals(CheckedOperationTimeoutException.class.getName()
- + ": test - failing node: " + TestConfig.IPV4_ADDR + ":11211",
+ + ": test - failing node: " + TestConfig.IPV4_ADDR + ":"
+ + TestConfig.PORT_NUMBER,
new CheckedOperationTimeoutException("test", op).toString());
}
@@ -63,11 +64,12 @@ public void testNullOperation() {
public void testMultipleOperation() {
Collection<Operation> ops = new ArrayList<Operation>();
- ops.add(buildOp(11211));
+ ops.add(buildOp(TestConfig.PORT_NUMBER));
ops.add(buildOp(64212));
assertEquals(CheckedOperationTimeoutException.class.getName()
- + ": test - failing nodes: " + TestConfig.IPV4_ADDR + ":11211, "
- + TestConfig.IPV4_ADDR + ":64212",
+ + ": test - failing nodes: " + TestConfig.IPV4_ADDR + ":"
+ + TestConfig.PORT_NUMBER + ", " + TestConfig.IPV4_ADDR
+ + ":64212",
new CheckedOperationTimeoutException("test", ops).toString());
}

0 comments on commit 36e4014

Please sign in to comment.