Skip to content
Browse files

Hardening test utils and tests to reduce the number of intermittent

BindException errors due to a TOCTOU issue with getLocalCluster.

The main improvement is the addition of
ServerTestUtils.startVoldemortCluster that wraps getLocalCluster and a
bunch of startVoldemortServer calls in a retry loop based on wether a
BindException occurs. This is suitable to ~75% of our test cases that
use getLocalCluster.

test/common/voldemort/ServerTestUtils.java
- Added startVoldemortCluster

test/unit/voldemort/utils/ServerTestUtilsTest.java
- Tests for ServerTestUtils to reproduce intermittent failures

src/java/voldemort/server/VoldemortServer.java
- TODO note about method that plays a role in another intermittent test failure invovling cluster.xml

Switched test to use startVoldemortCluster
  test/unit/voldemort/client/AdminServiceBasicTest.java
  test/unit/voldemort/client/rebalance/AdminRebalanceTest.java
  test/unit/voldemort/cluster/failuredetector/ServerStoreVerifierTest.java
  test/unit/voldemort/server/EndToEndTest.java
  test/unit/voldemort/server/socket/NioStatsJmxTest.java
  test/unit/voldemort/store/readonly/swapper/StoreSwapperTest.java
  test/unit/voldemort/store/rebalancing/RebootstrappingStoreTest.java
  test/unit/voldemort/versioning/ChainedInconsistencyResolverTest.java

Junit3 -> Junit 4
  test/unit/voldemort/client/AdminServiceBasicTest.java
  test/unit/voldemort/client/rebalance/AdminRebalanceTest.java
  test/unit/voldemort/server/gossip/GossiperTest.java
  test/unit/voldemort/server/socket/NioStatsJmxTest.java
  test/unit/voldemort/store/readonly/swapper/StoreSwapperTest.java
  test/unit/voldemort/versioning/ChainedInconsistencyResolverTest.java

Annotated with a TODO about the test still needing to be hardened
against TOCTOU issue with getLocalCluster:
  test/integration/voldemort/performance/RoutedStoreParallelismTest.java
  test/unit/voldemort/client/rebalance/RebalanceTest.java
  test/unit/voldemort/scheduled/StreamingSlopPusherTest.java
  test/unit/voldemort/server/gossip/GossiperTest.java
  • Loading branch information...
1 parent 03c60ce commit de66f98238f10a473e9dfa1eef81174b61be0a19 @jayjwylie jayjwylie committed
View
4 src/java/voldemort/server/VoldemortServer.java
@@ -91,10 +91,13 @@ public VoldemortServer(VoldemortConfig config) {
this.services = createServices();
}
+ // TODO: Should we use a different VoldemortServer construction depending on
+ // whether cluster is written previously!?!?! (cluster.xml issue)
public VoldemortServer(VoldemortConfig config, Cluster cluster) {
super(ServiceType.VOLDEMORT);
this.voldemortConfig = config;
this.identityNode = cluster.getNodeById(voldemortConfig.getNodeId());
+
this.checkHostName();
this.storeRepository = new StoreRepository();
// update cluster details in metaDataStore
@@ -220,6 +223,7 @@ private void checkHostName() {
rebalancer);
if(voldemortConfig.getUseNioConnector()) {
+
logger.info("Using NIO Connector for Admin Service.");
services.add(new NioSocketService(adminRequestHandlerFactory,
identityNode.getAdminPort(),
View
63 test/common/voldemort/ServerTestUtils.java
@@ -20,6 +20,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
+import java.net.BindException;
import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.Collections;
@@ -33,6 +34,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.http.client.HttpClient;
+import org.apache.log4j.Logger;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
@@ -86,6 +88,8 @@
*/
public class ServerTestUtils {
+ private static final Logger logger = Logger.getLogger(ServerTestUtils.class.getName());
+
public static StoreRepository getStores(String storeName, String clusterXml, String storesXml) {
StoreRepository repository = new StoreRepository();
Store<ByteArray, byte[], byte[]> store = new InMemoryStorageEngine<ByteArray, byte[], byte[]>(storeName);
@@ -234,6 +238,7 @@ public static int findFreePort() {
* Return an array of free ports as chosen by new ServerSocket(0)
*/
public static int[] findFreePorts(int n) {
+ logger.info("findFreePorts cannot guarantee that ports identified as free will still be free when used. This is effectively a TOCTOU issue. Expect intermittent BindException when \"free\" ports are used.");
int[] ports = new int[n];
ServerSocket[] sockets = new ServerSocket[n];
try {
@@ -663,6 +668,9 @@ public static void stopVoldemortServer(VoldemortServer server) throws IOExceptio
public static VoldemortServer startVoldemortServer(SocketStoreFactory socketStoreFactory,
VoldemortConfig config,
Cluster cluster) {
+
+ // TODO: Should this use VoldemortServer(config) instead!?!?!?
+ // (config.xml)
VoldemortServer server = new VoldemortServer(config, cluster);
server.start();
@@ -709,4 +717,59 @@ public static void waitForServerStart(SocketStoreFactory socketStoreFactory, Nod
if(!success)
throw new RuntimeException("Failed to connect with server:" + node);
}
+
+ protected static Cluster internalStartVoldemortCluster(int numServers,
+ VoldemortServer[] voldemortServers,
+ int[][] partitionMap,
+ SocketStoreFactory socketStoreFactory,
+ boolean useNio,
+ String clusterFile,
+ String storeFile,
+ Properties properties)
+ throws IOException {
+ Cluster cluster = ServerTestUtils.getLocalCluster(numServers, partitionMap);
+ for(int i = 0; i < numServers; i++) {
+ voldemortServers[i] = ServerTestUtils.startVoldemortServer(socketStoreFactory,
+ ServerTestUtils.createServerConfig(useNio,
+ i,
+ TestUtils.createTempDir()
+ .getAbsolutePath(),
+ clusterFile,
+ storeFile,
+ properties),
+ cluster);
+ }
+ return cluster;
+ }
+
+ public static Cluster startVoldemortCluster(int numServers,
+ VoldemortServer[] voldemortServers,
+ int[][] partitionMap,
+ SocketStoreFactory socketStoreFactory,
+ boolean useNio,
+ String clusterFile,
+ String storeFile,
+ Properties properties) throws IOException {
+ boolean started = false;
+ Cluster cluster = null;
+
+ while(!started) {
+ try {
+ cluster = internalStartVoldemortCluster(numServers,
+ voldemortServers,
+ partitionMap,
+ socketStoreFactory,
+ useNio,
+ clusterFile,
+ storeFile,
+ properties);
+ started = true;
+ } catch(BindException be) {
+ logger.debug("Caught BindException when starting cluster. Will retry.");
+ }
+ }
+
+ return cluster;
+ }
+
}
View
2 test/integration/voldemort/performance/RoutedStoreParallelismTest.java
@@ -161,6 +161,8 @@ public static void main(String[] args) throws Throwable {
clientConfig.getSocketBufferSize(),
clientConfig.getSocketKeepAlive());
+ // TODO: add a variant of ServerTestUtils.startVoldemortCluster that
+ // accepts StoreDefinitions in the interface.
for(int i = 0; i < cluster.getNumberOfNodes(); i++) {
VoldemortConfig config = ServerTestUtils.createServerConfig(true,
i,
View
36 test/unit/voldemort/client/AdminServiceBasicTest.java
@@ -21,6 +21,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
+
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -121,32 +122,21 @@ public AdminServiceBasicTest(boolean useNio) {
@Before
public void setUp() throws IOException {
- cluster = ServerTestUtils.getLocalCluster(2, new int[][] { { 0, 1, 2, 3 }, { 4, 5, 6, 7 } });
-
- servers = new VoldemortServer[2];
- storeDefs = new StoreDefinitionsMapper().readStoreList(new File(storesXmlfile));
-
+ int numServers = 2;
+ VoldemortServer[] servers = new VoldemortServer[numServers];
+ int partitionMap[][] = { { 0, 1, 2, 3 }, { 4, 5, 6, 7 } };
Properties serverProperties = new Properties();
serverProperties.setProperty("client.max.connections.per.node", "20");
+ ServerTestUtils.startVoldemortCluster(numServers,
+ servers,
+ partitionMap,
+ socketStoreFactory,
+ useNio,
+ null,
+ storesXmlfile,
+ serverProperties);
- servers[0] = ServerTestUtils.startVoldemortServer(socketStoreFactory,
- ServerTestUtils.createServerConfig(useNio,
- 0,
- TestUtils.createTempDir()
- .getAbsolutePath(),
- null,
- storesXmlfile,
- serverProperties),
- cluster);
- servers[1] = ServerTestUtils.startVoldemortServer(socketStoreFactory,
- ServerTestUtils.createServerConfig(useNio,
- 1,
- TestUtils.createTempDir()
- .getAbsolutePath(),
- null,
- storesXmlfile,
- serverProperties),
- cluster);
+ storeDefs = new StoreDefinitionsMapper().readStoreList(new File(storesXmlfile));
Properties adminProperties = new Properties();
adminProperties.setProperty("max_connections", "20");
View
116 test/unit/voldemort/client/rebalance/AdminRebalanceTest.java
@@ -111,10 +111,6 @@ public AdminRebalanceTest(boolean useNio) {
}
public void startThreeNodeRW() throws IOException {
- cluster = ServerTestUtils.getLocalCluster(3, new int[][] { { 0, 1, 2, 3 }, { 4, 5, 6, 7 },
- {} });
-
- servers = new VoldemortServer[3];
storeDef1 = ServerTestUtils.getStoreDef("test",
1,
1,
@@ -129,23 +125,24 @@ public void startThreeNodeRW() throws IOException {
1,
1,
RoutingStrategyType.CONSISTENT_STRATEGY);
- targetCluster = RebalanceUtils.createUpdatedCluster(cluster, 2, Lists.newArrayList(0));
File tempStoreXml = new File(TestUtils.createTempDir(), "stores.xml");
FileUtils.writeStringToFile(tempStoreXml,
new StoreDefinitionsMapper().writeStoreList(Lists.newArrayList(storeDef1,
storeDef2)));
- for(int nodeId = 0; nodeId < 3; nodeId++) {
- servers[nodeId] = ServerTestUtils.startVoldemortServer(socketStoreFactory,
- ServerTestUtils.createServerConfig(useNio,
- nodeId,
- TestUtils.createTempDir()
- .getAbsolutePath(),
- null,
- tempStoreXml.getAbsolutePath(),
- new Properties()),
- cluster);
- }
+ int numServers = 3;
+ servers = new VoldemortServer[numServers];
+ int partitionMap[][] = { { 0, 1, 2, 3 }, { 4, 5, 6, 7 }, {} };
+ cluster = ServerTestUtils.startVoldemortCluster(numServers,
+ servers,
+ partitionMap,
+ socketStoreFactory,
+ useNio,
+ null,
+ tempStoreXml.getAbsolutePath(),
+ new Properties());
+
+ targetCluster = RebalanceUtils.createUpdatedCluster(cluster, 2, Lists.newArrayList(0));
RebalanceClusterPlan plan = new RebalanceClusterPlan(cluster,
targetCluster,
Lists.newArrayList(storeDef1,
@@ -156,10 +153,6 @@ public void startThreeNodeRW() throws IOException {
}
public void startFourNodeRW() throws IOException {
- cluster = ServerTestUtils.getLocalCluster(4, new int[][] { { 0, 1, 2, 3 }, { 4, 5, 6, 7 },
- { 8, 9, 10, 11 }, {} });
-
- servers = new VoldemortServer[4];
storeDef1 = ServerTestUtils.getStoreDef("test",
2,
1,
@@ -174,23 +167,24 @@ public void startFourNodeRW() throws IOException {
1,
1,
RoutingStrategyType.CONSISTENT_STRATEGY);
- targetCluster = RebalanceUtils.createUpdatedCluster(cluster, 3, Lists.newArrayList(0));
File tempStoreXml = new File(TestUtils.createTempDir(), "stores.xml");
FileUtils.writeStringToFile(tempStoreXml,
new StoreDefinitionsMapper().writeStoreList(Lists.newArrayList(storeDef1,
storeDef2)));
- for(int nodeId = 0; nodeId < 4; nodeId++) {
- servers[nodeId] = ServerTestUtils.startVoldemortServer(socketStoreFactory,
- ServerTestUtils.createServerConfig(useNio,
- nodeId,
- TestUtils.createTempDir()
- .getAbsolutePath(),
- null,
- tempStoreXml.getAbsolutePath(),
- new Properties()),
- cluster);
- }
+ int numServers = 4;
+ servers = new VoldemortServer[numServers];
+ int partitionMap[][] = { { 0, 1, 2, 3 }, { 4, 5, 6, 7 }, { 8, 9, 10, 11 }, {} };
+ cluster = ServerTestUtils.startVoldemortCluster(numServers,
+ servers,
+ partitionMap,
+ socketStoreFactory,
+ useNio,
+ null,
+ tempStoreXml.getAbsolutePath(),
+ new Properties());
+
+ targetCluster = RebalanceUtils.createUpdatedCluster(cluster, 3, Lists.newArrayList(0));
RebalanceClusterPlan plan = new RebalanceClusterPlan(cluster,
targetCluster,
Lists.newArrayList(storeDef1,
@@ -201,10 +195,6 @@ public void startFourNodeRW() throws IOException {
}
public void startFourNodeRO() throws IOException {
- cluster = ServerTestUtils.getLocalCluster(4, new int[][] { { 0, 1, 2, 3 }, { 4, 5, 6, 7 },
- { 8, 9, 10, 11 }, {} });
-
- servers = new VoldemortServer[4];
storeDef1 = new StoreDefinitionBuilder().setName("test")
.setType(ReadOnlyStorageConfiguration.TYPE_NAME)
.setKeySerializer(new SerializerDefinition("string"))
@@ -229,23 +219,24 @@ public void startFourNodeRO() throws IOException {
.setPreferredWrites(1)
.setRequiredWrites(1)
.build();
- targetCluster = RebalanceUtils.createUpdatedCluster(cluster, 3, Lists.newArrayList(0));
File tempStoreXml = new File(TestUtils.createTempDir(), "stores.xml");
FileUtils.writeStringToFile(tempStoreXml,
new StoreDefinitionsMapper().writeStoreList(Lists.newArrayList(storeDef1,
storeDef2)));
- for(int nodeId = 0; nodeId < 4; nodeId++) {
- servers[nodeId] = ServerTestUtils.startVoldemortServer(socketStoreFactory,
- ServerTestUtils.createServerConfig(useNio,
- nodeId,
- TestUtils.createTempDir()
- .getAbsolutePath(),
- null,
- tempStoreXml.getAbsolutePath(),
- new Properties()),
- cluster);
- }
+ int numServers = 4;
+ servers = new VoldemortServer[numServers];
+ int partitionMap[][] = { { 0, 1, 2, 3 }, { 4, 5, 6, 7 }, { 8, 9, 10, 11 }, {} };
+ cluster = ServerTestUtils.startVoldemortCluster(numServers,
+ servers,
+ partitionMap,
+ socketStoreFactory,
+ useNio,
+ null,
+ tempStoreXml.getAbsolutePath(),
+ new Properties());
+
+ targetCluster = RebalanceUtils.createUpdatedCluster(cluster, 3, Lists.newArrayList(0));
RebalanceClusterPlan plan = new RebalanceClusterPlan(cluster,
targetCluster,
Lists.newArrayList(storeDef1,
@@ -256,10 +247,6 @@ public void startFourNodeRO() throws IOException {
}
public void startFourNodeRORW() throws IOException {
- cluster = ServerTestUtils.getLocalCluster(4, new int[][] { { 0, 1, 2, 3 }, { 4, 5, 6, 7 },
- { 8, 9, 10, 11 }, {} });
-
- servers = new VoldemortServer[4];
storeDef1 = new StoreDefinitionBuilder().setName("test")
.setType(ReadOnlyStorageConfiguration.TYPE_NAME)
.setKeySerializer(new SerializerDefinition("string"))
@@ -299,25 +286,26 @@ public void startFourNodeRORW() throws IOException {
1,
RoutingStrategyType.CONSISTENT_STRATEGY);
- targetCluster = RebalanceUtils.createUpdatedCluster(cluster, 3, Lists.newArrayList(0));
File tempStoreXml = new File(TestUtils.createTempDir(), "stores.xml");
FileUtils.writeStringToFile(tempStoreXml,
new StoreDefinitionsMapper().writeStoreList(Lists.newArrayList(storeDef1,
storeDef2,
storeDef3,
storeDef4)));
- for(int nodeId = 0; nodeId < 4; nodeId++) {
- servers[nodeId] = ServerTestUtils.startVoldemortServer(socketStoreFactory,
- ServerTestUtils.createServerConfig(useNio,
- nodeId,
- TestUtils.createTempDir()
- .getAbsolutePath(),
- null,
- tempStoreXml.getAbsolutePath(),
- new Properties()),
- cluster);
- }
+ int numServers = 4;
+ servers = new VoldemortServer[numServers];
+ int partitionMap[][] = { { 0, 1, 2, 3 }, { 4, 5, 6, 7 }, { 8, 9, 10, 11 }, {} };
+ cluster = ServerTestUtils.startVoldemortCluster(numServers,
+ servers,
+ partitionMap,
+ socketStoreFactory,
+ useNio,
+ null,
+ tempStoreXml.getAbsolutePath(),
+ new Properties());
+
+ targetCluster = RebalanceUtils.createUpdatedCluster(cluster, 3, Lists.newArrayList(0));
// Make plan only with RO stores
RebalanceClusterPlan plan = new RebalanceClusterPlan(cluster,
targetCluster,
View
1 test/unit/voldemort/client/rebalance/RebalanceTest.java
@@ -81,6 +81,7 @@ protected Cluster getCurrentCluster(int nodeId) {
}
}
+ // TODO: refactor to take advantage of ServerTestUtils.startVoldemortCluster
@Override
protected Cluster startServers(Cluster cluster,
String storeXmlFile,
View
35 test/unit/voldemort/cluster/failuredetector/ServerStoreVerifierTest.java
@@ -31,12 +31,12 @@
import org.junit.runners.Parameterized.Parameters;
import voldemort.ServerTestUtils;
-import voldemort.TestUtils;
import voldemort.VoldemortException;
import voldemort.cluster.Cluster;
import voldemort.cluster.Node;
import voldemort.common.service.ServiceType;
import voldemort.server.VoldemortConfig;
+import voldemort.server.ServiceType;
import voldemort.server.VoldemortServer;
import voldemort.server.storage.StorageService;
import voldemort.store.socket.SocketStoreFactory;
@@ -45,7 +45,7 @@
@RunWith(Parameterized.class)
public class ServerStoreVerifierTest {
- private final String storeDefFile = "test/common/voldemort/config/single-store.xml";
+ private final String storesXmlfile = "test/common/voldemort/config/single-store.xml";
private final Map<Integer, VoldemortServer> serverMap = new HashMap<Integer, VoldemortServer>();
@@ -69,23 +69,20 @@ public ServerStoreVerifierTest(boolean useNio) {
@Before
public void setUp() throws IOException {
- cluster = ServerTestUtils.getLocalCluster(2, new int[][] { { 0 }, { 1 } });
-
- for(int i = 0; i < cluster.getNumberOfNodes(); i++) {
- Properties properties = new Properties();
-
- VoldemortConfig config = ServerTestUtils.createServerConfig(useNio,
- i,
- TestUtils.createTempDir()
- .getAbsolutePath(),
- null,
- storeDefFile,
- properties);
-
- VoldemortServer server = ServerTestUtils.startVoldemortServer(socketStoreFactory,
- config,
- cluster);
- serverMap.put(i, server);
+ int numServers = 2;
+ VoldemortServer[] servers = new VoldemortServer[numServers];
+ int partitionMap[][] = { { 0 }, { 1 } };
+ cluster = ServerTestUtils.startVoldemortCluster(numServers,
+ servers,
+ partitionMap,
+ socketStoreFactory,
+ useNio,
+ null,
+ storesXmlfile,
+ new Properties());
+
+ for(int i = 0; i < numServers; i++) {
+ serverMap.put(i, servers[i]);
}
}
View
1 test/unit/voldemort/scheduled/StreamingSlopPusherTest.java
@@ -78,6 +78,7 @@ public void setUp() throws Exception {
}
}
+ // TODO: Refactor to take advantage of ServerTestUtils.startVoldemortCluster
private void startServers(int... nodeIds) {
for(int nodeId: nodeIds) {
if(nodeId < NUM_SERVERS) {
View
37 test/unit/voldemort/server/EndToEndTest.java
@@ -5,10 +5,8 @@
import static org.junit.Assert.assertNull;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -20,7 +18,6 @@
import org.junit.runners.Parameterized.Parameters;
import voldemort.ServerTestUtils;
-import voldemort.TestUtils;
import voldemort.client.ClientConfig;
import voldemort.client.SocketStoreClientFactory;
import voldemort.client.StoreClient;
@@ -49,8 +46,6 @@
32 * 1024);
private final boolean useNio;
- private List<VoldemortServer> servers;
- private Cluster cluster;
private StoreClient<String, String> storeClient;
public EndToEndTest(boolean useNio) {
@@ -64,26 +59,18 @@ public EndToEndTest(boolean useNio) {
@Before
public void setUp() throws IOException {
- cluster = ServerTestUtils.getLocalCluster(2, new int[][] { { 0, 2, 4, 6 }, { 1, 3, 5, 7 } });
- servers = new ArrayList<VoldemortServer>();
- servers.add(ServerTestUtils.startVoldemortServer(socketStoreFactory,
- ServerTestUtils.createServerConfig(useNio,
- 0,
- TestUtils.createTempDir()
- .getAbsolutePath(),
- null,
- STORES_XML,
- new Properties()),
- cluster));
- servers.add(ServerTestUtils.startVoldemortServer(socketStoreFactory,
- ServerTestUtils.createServerConfig(useNio,
- 1,
- TestUtils.createTempDir()
- .getAbsolutePath(),
- null,
- STORES_XML,
- new Properties()),
- cluster));
+ int numServers = 2;
+ VoldemortServer[] servers = new VoldemortServer[numServers];
+ int partitionMap[][] = { { 0, 2, 4, 6 }, { 1, 3, 5, 7 } };
+ Cluster cluster = ServerTestUtils.startVoldemortCluster(numServers,
+ servers,
+ partitionMap,
+ socketStoreFactory,
+ useNio,
+ null,
+ STORES_XML,
+ new Properties());
+
Node node = cluster.getNodeById(0);
String bootstrapUrl = "tcp://" + node.getHost() + ":" + node.getSocketPort();
StoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
View
28 test/unit/voldemort/server/gossip/GossiperTest.java
@@ -1,5 +1,7 @@
package voldemort.server.gossip;
+import static org.junit.Assert.assertEquals;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -10,8 +12,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import junit.framework.TestCase;
-
+import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -38,7 +39,9 @@
* Tests {@link voldemort.server.gossip.Gossiper}
*/
@RunWith(Parameterized.class)
-public class GossiperTest extends TestCase {
+public class GossiperTest {
+
+ private static final Logger logger = Logger.getLogger(GossiperTest.class.getName());
private List<VoldemortServer> servers = new ArrayList<VoldemortServer>();
private Cluster cluster;
@@ -61,9 +64,8 @@ public GossiperTest(boolean useNio) {
return Arrays.asList(new Object[][] { { false }, { true } });
}
- @Override
@Before
- public void setUp() throws IOException {
+ public void setUp() {
props.put("enable.gossip", "true");
props.put("gossip.interval.ms", "250");
props.put("socket.buffer.size", String.valueOf(socketBufferSize));
@@ -76,6 +78,8 @@ public void setUp() throws IOException {
ExecutorService executorService = Executors.newFixedThreadPool(3);
final CountDownLatch countDownLatch = new CountDownLatch(3);
+ // TODO: Add a variant of ServerTestUtils.startVoldemortCluster that
+ // starts servers in parallel?
for(int i = 0; i < 3; i++) {
final int j = i;
executorService.submit(new Runnable() {
@@ -93,6 +97,9 @@ public void run() {
cluster));
countDownLatch.countDown();
} catch(IOException e) {
+ logger.error("Caught IOException during parallel server start: "
+ + e.getMessage());
+ e.printStackTrace();
throw new RuntimeException();
}
}
@@ -106,7 +113,6 @@ public void run() {
}
}
- @Override
@After
public void tearDown() {
socketStoreFactory.close();
@@ -116,7 +122,9 @@ private AdminClient getAdminClient(Cluster newCluster) {
return new AdminClient(newCluster, new AdminClientConfig());
}
- @Test
+ // Protect against this test running forever until the root cause of running
+ // forever is found.
+ @Test(timeout = 1800)
public void testGossiper() throws Exception {
// First create a new cluster:
// Allocate ports for all nodes in the new cluster, to match existing
@@ -127,7 +135,11 @@ public void testGossiper() throws Exception {
for(int i = 0, j = 0; i < originalSize; i++, j += 3) {
Node node = cluster.getNodeById(i);
System.arraycopy(new int[] { node.getHttpPort(), node.getSocketPort(),
- node.getAdminPort() }, 0, ports, j, 3);
+ node.getAdminPort() },
+ 0,
+ ports,
+ j,
+ 3);
}
System.arraycopy(ServerTestUtils.findFreePorts(3), 0, ports, numOriginalPorts, 3);
View
39 test/unit/voldemort/server/socket/NioStatsJmxTest.java
@@ -16,6 +16,8 @@
package voldemort.server.socket;
+import static org.junit.Assert.assertEquals;
+
import java.lang.management.ManagementFactory;
import java.util.Properties;
import java.util.Random;
@@ -24,18 +26,14 @@
import javax.management.MBeanServer;
import javax.management.ObjectName;
-import junit.framework.TestCase;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import voldemort.ServerTestUtils;
-import voldemort.TestUtils;
import voldemort.client.ClientConfig;
import voldemort.cluster.Cluster;
import voldemort.cluster.Node;
-import voldemort.server.VoldemortConfig;
import voldemort.server.VoldemortServer;
import voldemort.server.niosocket.NioSocketService;
import voldemort.store.Store;
@@ -49,16 +47,15 @@
* Unit test for NIO selector connection stats
*
*/
-public class NioStatsJmxTest extends TestCase {
+public class NioStatsJmxTest {
private VoldemortServer server;
private Store<ByteArray, byte[], byte[]> socketStore;
private static final int MAX_TRAFFIC_TIME_MS = 2000;
- @Override
@Before
public void setUp() throws Exception {
- String storeDefinitionFile = "test/common/voldemort/config/single-store.xml";
+ String storesXmlfile = "test/common/voldemort/config/single-store.xml";
ClientConfig clientConfig = new ClientConfig().setMaxConnectionsPerNode(1).setMaxThreads(1);
SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(clientConfig.getSelectors(),
clientConfig.getMaxConnectionsPerNode(),
@@ -66,17 +63,23 @@ public void setUp() throws Exception {
clientConfig.getSocketTimeout(TimeUnit.MILLISECONDS),
clientConfig.getSocketBufferSize(),
clientConfig.getSocketKeepAlive());
- Cluster cluster = ServerTestUtils.getLocalCluster(1);
+
Properties props = new Properties();
props.put("jmx.enable", "true");
- VoldemortConfig config = ServerTestUtils.createServerConfig(true,
- 0,
- TestUtils.createTempDir()
- .getAbsolutePath(),
- null,
- storeDefinitionFile,
- props);
- server = ServerTestUtils.startVoldemortServer(socketStoreFactory, config, cluster);
+
+ int numServers = 1;
+ VoldemortServer[] servers = new VoldemortServer[numServers];
+ Cluster cluster = ServerTestUtils.startVoldemortCluster(numServers,
+ servers,
+ null,
+ socketStoreFactory,
+ true,
+ null,
+ storesXmlfile,
+ props);
+
+ server = servers[0];
+
for(Node node: cluster.getNodes()) {
socketStore = ServerTestUtils.getSocketStore(socketStoreFactory,
"test",
@@ -90,10 +93,9 @@ public void testActiveConnectionCount() throws Exception {
// generate some traffic,
Random dataGen = new Random();
long start = System.currentTimeMillis();
- long now = 0;
byte[] data = new byte[256];
- while(((now = System.currentTimeMillis()) - start) <= MAX_TRAFFIC_TIME_MS) {
+ while(((System.currentTimeMillis()) - start) <= MAX_TRAFFIC_TIME_MS) {
dataGen.nextBytes(data);
ByteArray key = new ByteArray(data);
socketStore.put(key, new Versioned<byte[]>(data), null);
@@ -107,7 +109,6 @@ public void testActiveConnectionCount() throws Exception {
assertEquals(1, beanserver.getAttribute(name, "numActiveConnections"));
}
- @Override
@After
public void tearDown() {
server.stop();
View
73 test/unit/voldemort/store/readonly/swapper/StoreSwapperTest.java
@@ -16,6 +16,10 @@
package voldemort.store.readonly.swapper;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@@ -25,8 +29,6 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import junit.framework.TestCase;
-
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.junit.After;
@@ -59,7 +61,7 @@
/**
*
*/
-public class StoreSwapperTest extends TestCase {
+public class StoreSwapperTest {
private static int NUM_NODES = 3;
private static String STORE_NAME = "test";
@@ -71,49 +73,51 @@
private VoldemortServer[] servers;
private Cluster cluster;
private AdminClient adminClient;
- private StoreDefinition storeDef;
private File baseDirs[];
- @Override
- @Before
- public void setUp() throws IOException {
- cluster = ServerTestUtils.getLocalCluster(NUM_NODES);
- servers = new VoldemortServer[NUM_NODES];
- baseDirs = new File[NUM_NODES];
- storeDef = new StoreDefinitionBuilder().setName(STORE_NAME)
- .setType(ReadOnlyStorageConfiguration.TYPE_NAME)
- .setKeySerializer(serializerDef)
- .setValueSerializer(serializerDef)
- .setRoutingPolicy(RoutingTier.SERVER)
- .setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY)
- .setReplicationFactor(2)
- .setPreferredReads(1)
- .setRequiredReads(1)
- .setPreferredWrites(1)
- .setRequiredWrites(1)
- .build();
+ protected String constructStoresXml() throws IOException {
+ StoreDefinition storeDef = new StoreDefinitionBuilder().setName(STORE_NAME)
+ .setType(ReadOnlyStorageConfiguration.TYPE_NAME)
+ .setKeySerializer(serializerDef)
+ .setValueSerializer(serializerDef)
+ .setRoutingPolicy(RoutingTier.SERVER)
+ .setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY)
+ .setReplicationFactor(2)
+ .setPreferredReads(1)
+ .setRequiredReads(1)
+ .setPreferredWrites(1)
+ .setRequiredWrites(1)
+ .build();
File storesXml = new File(TestUtils.createTempDir(), "stores.xml");
-
StoreDefinitionsMapper storeDefMapper = new StoreDefinitionsMapper();
FileWriter writer = new FileWriter(storesXml);
writer.write(storeDefMapper.writeStoreList(Lists.newArrayList(storeDef)));
writer.close();
- File baseTempDir = TestUtils.createTempDir();
+ return storesXml.getAbsolutePath();
+ }
+ @Before
+ public void setUp() throws IOException {
+ String storesXmlFile = constructStoresXml();
+
+ servers = new VoldemortServer[NUM_NODES];
Properties props = new Properties();
props.put("readonly.backups", "1");
+ cluster = ServerTestUtils.startVoldemortCluster(NUM_NODES,
+ servers,
+ null,
+ socketStoreFactory,
+ false,
+ null,
+ storesXmlFile,
+ props);
+
+ baseDirs = new File[NUM_NODES];
for(int nodeId = 0; nodeId < NUM_NODES; nodeId++) {
- servers[nodeId] = ServerTestUtils.startVoldemortServer(socketStoreFactory,
- ServerTestUtils.createServerConfig(false,
- nodeId,
- baseTempDir.getAbsolutePath(),
- null,
- storesXml.getAbsolutePath(),
- props),
- cluster);
- baseDirs[nodeId] = new File(baseTempDir + "/node-" + nodeId + "/data/read-only/"
+ String baseDir = servers[nodeId].getVoldemortConfig().getDataDirectory();
+ baseDirs[nodeId] = new File(baseDir + "/node-" + nodeId + "/data/read-only/"
+ STORE_NAME);
}
@@ -121,9 +125,8 @@ public void setUp() throws IOException {
}
- @Override
@After
- public void tearDown() throws IOException, InterruptedException {
+ public void tearDown() throws IOException {
adminClient.stop();
for(VoldemortServer server: servers) {
ServerTestUtils.stopVoldemortServer(server);
View
37 test/unit/voldemort/store/rebalancing/RebootstrappingStoreTest.java
@@ -14,7 +14,6 @@
import org.junit.Test;
import voldemort.ServerTestUtils;
-import voldemort.TestUtils;
import voldemort.client.ClientConfig;
import voldemort.client.SocketStoreClientFactory;
import voldemort.client.StoreClient;
@@ -41,40 +40,40 @@
private final static String STORE_NAME = "test";
private final static String STORES_XML = "test/common/voldemort/config/single-store.xml";
- private final int[][] startCluster = new int[][] { { 0, 1 }, {} };
-
- private Map<String, String> entries;
private Cluster cluster;
private List<VoldemortServer> servers;
private StoreClient<String, String> storeClient;
@Before
public void setUp() throws Exception {
- entries = Maps.newHashMap();
- entries.put("a", "1");
- entries.put("b", "2");
- cluster = ServerTestUtils.getLocalCluster(2, startCluster);
- servers = Lists.newArrayList();
- Properties props = new Properties();
SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2,
10000,
100000,
32 * 1024);
- for(Node node: cluster.getNodes()) {
- VoldemortConfig config = ServerTestUtils.createServerConfig(false,
- node.getId(),
- TestUtils.createTempDir()
- .getAbsolutePath(),
- null,
- STORES_XML,
- props);
- servers.add(ServerTestUtils.startVoldemortServer(socketStoreFactory, config, cluster));
+ int numServers = 2;
+ VoldemortServer[] voldemortServers = new VoldemortServer[numServers];
+ int partitionMap[][] = { { 0, 1 }, {} };
+ cluster = ServerTestUtils.startVoldemortCluster(numServers,
+ voldemortServers,
+ partitionMap,
+ socketStoreFactory,
+ false,
+ null,
+ STORES_XML,
+ new Properties());
+
+ servers = Lists.newArrayList();
+ for(int i = 0; i < numServers; ++i) {
+ servers.add(voldemortServers[i]);
}
String bootstrapUrl = cluster.getNodeById(0).getSocketUrl().toString();
storeClient = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl)).getStoreClient(STORE_NAME);
+ Map<String, String> entries = Maps.newHashMap();
+ entries.put("a", "1");
+ entries.put("b", "2");
for(Map.Entry<String, String> entry: entries.entrySet())
storeClient.put(entry.getKey(), entry.getValue());
}
View
132 test/unit/voldemort/utils/ServerTestUtilsTest.java
@@ -16,12 +16,14 @@
package voldemort.utils;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.channels.ServerSocketChannel;
import java.util.Properties;
-import org.junit.Before;
import org.junit.Test;
import voldemort.ServerTestUtils;
@@ -33,25 +35,41 @@
public class ServerTestUtilsTest {
- // private static String storesXmlfile = "test/common/voldemort/config/single-store.xml";
private static String storesXmlfile = "test/common/voldemort/config/stores.xml";
private SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2,
10000,
100000,
32 * 1024);
- @Before
- public void setUp() throws IOException {
- /*-
- Cluster cluster = ServerTestUtils.getLocalCluster(1, new int[][] { { 0, 1, 2, 3, 4, 5, 6,
- 7, 8 } });
- */
+ public void testStartVoldemortCluster() throws IOException {
+ int numServers = 8;
+ VoldemortServer[] servers = new VoldemortServer[numServers];
+ int partitionMap[][] = { { 0 }, { 1 }, { 2 }, { 3 }, { 4 }, { 5 }, { 6 }, { 7 } };
+ ServerTestUtils.startVoldemortCluster(numServers,
+ servers,
+ partitionMap,
+ socketStoreFactory,
+ true,
+ null,
+ storesXmlfile,
+ new Properties());
+ }
+
+ @Test
+ public void startMultipleVoldemortClusters() throws IOException {
+ for(int i = 0; i < 10; i++) {
+ testStartVoldemortCluster();
+ }
+ }
+
+ // * START : TESTS THAT HELPED FIND ROOT CAUSE OF BindException PROBLEM *
+ // @Test
+ public void startMultipleVoldemortServers() throws IOException {
Cluster cluster = ServerTestUtils.getLocalCluster(8, new int[][] { { 0 }, { 1 }, { 2 },
{ 3 }, { 4 }, { 5 }, { 6 }, { 7 } });
VoldemortServer[] servers = new VoldemortServer[8];
- // for(int i = 0; i < 1; i++) {
for(int i = 0; i < 8; i++) {
servers[i] = ServerTestUtils.startVoldemortServer(socketStoreFactory,
ServerTestUtils.createServerConfig(true,
@@ -63,10 +81,102 @@ public void setUp() throws IOException {
new Properties()),
cluster);
}
+ assertTrue(true);
}
- @Test
- public void startMultipleVoldemortServers() {
+ // @Test
+ public void startMultipleVoldemortServers10() {
+ for(int i = 0; i < 10; i++) {
+ boolean started = false;
+ boolean caught = false;
+ while(!started) {
+ try {
+ startMultipleVoldemortServers();
+ started = true;
+ } catch(IOException ioe) {
+ System.err.println("CAUGHT BIND ERROR! Trying again...");
+ ioe.printStackTrace();
+ caught = true;
+ }
+ }
+ assertFalse(caught);
+ }
+ }
+
+ // @Test
+ public void testFindFreePort() throws Exception {
+ ServerSocketChannel serverSocketChannel;
+ try {
+ serverSocketChannel = ServerSocketChannel.open();
+ } catch(IOException ioe) {
+ ioe.printStackTrace();
+ assertTrue(false);
+ return;
+ }
+
+ int port = ServerTestUtils.findFreePort();
+
+ try {
+ serverSocketChannel.socket().bind(new InetSocketAddress(port));
+ } catch(IOException ioe) {
+ ioe.printStackTrace();
+ assertTrue(false);
+ return;
+ }
+
assertTrue(true);
}
+
+ // @Test
+ public void testFindFreePort1000() throws Exception {
+ for(int i = 0; i < 1000; i++) {
+ testFindFreePort();
+ }
+ }
+
+ // @Test
+ public void testFindFreePorts() throws Exception {
+ int numPorts = 25000;
+ ServerSocketChannel serverSocketChannel[] = new ServerSocketChannel[numPorts];
+ int ports[] = ServerTestUtils.findFreePorts(numPorts);
+
+ for(int i = 0; i < numPorts; i++) {
+ boolean bound = false;
+ while(!bound) {
+ try {
+ serverSocketChannel[i] = ServerSocketChannel.open();
+ serverSocketChannel[i].socket().bind(new InetSocketAddress(ports[i]));
+ serverSocketChannel[i].socket().setReuseAddress(true);
+ bound = true;
+ } catch(IOException ioe) {
+ System.err.println("Attempt: " + i + ", port: " + ports[i]);
+ ioe.printStackTrace();
+ Thread.sleep(10);
+ }
+ }
+ }
+
+ for(int i = 0; i < numPorts; i++) {
+ try {
+ serverSocketChannel[i].socket().close();
+ } catch(IOException ioe) {
+ System.err.println("Attempt: " + i + ", port: " + ports[i]);
+ ioe.printStackTrace();
+ assertTrue(false);
+ return;
+ }
+ }
+
+ assertTrue(true);
+ }
+
+ // @Test
+ public void testFindFreePorts100() throws Exception {
+ for(int i = 0; i < 100; i++) {
+ System.out.println("testFindFreePorts100: " + i);
+ testFindFreePorts();
+ }
+ }
+ // ** END : TESTS THAT HELPED FIND ROOT CAUSE OF BindException PROBLEM **
+
}
View
55 test/unit/voldemort/versioning/ChainedInconsistencyResolverTest.java
@@ -1,18 +1,17 @@
package voldemort.versioning;
+import static org.junit.Assert.assertEquals;
+
import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
-import junit.framework.TestCase;
-
import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import voldemort.ServerTestUtils;
import voldemort.TestUtils;
-import voldemort.VoldemortTestConstants;
import voldemort.client.ClientConfig;
import voldemort.client.SocketStoreClientFactory;
import voldemort.client.StoreClient;
@@ -30,50 +29,33 @@
* Test to ensure that the TimeBasedInconsistencyResolver returns a max Vector
* clock with the max timestamp.
*/
-public class ChainedInconsistencyResolverTest extends TestCase {
+public class ChainedInconsistencyResolverTest {
private static final String KEY = "XYZ";
private Versioned<String> v1, v2;
private Versioned<String> conflict1, conflict2, conflict3, conflict4, conflict5, conflict6;
- private Node node;
- private Cluster cluster;
private StoreClient<String, String> defaultStoreClient;
private Store<ByteArray, byte[], byte[]> socketStore;
- private List<VoldemortServer> servers;
private final SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2,
10000,
100000,
32 * 1024);
- private final boolean useNio = false;
private static final String STORES_XML = "test/common/voldemort/config/single-store.xml";
- @Override
+ @Before
public void setUp() throws IOException {
- VoldemortTestConstants.getSingleStoreDefinitionsXml();
- this.cluster = ServerTestUtils.getLocalCluster(2);
- this.node = cluster.getNodes().iterator().next();
- String bootstrapUrl = "tcp://" + node.getHost() + ":" + node.getSocketPort();
- StoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
- servers = new ArrayList<VoldemortServer>();
- servers.add(ServerTestUtils.startVoldemortServer(socketStoreFactory,
- ServerTestUtils.createServerConfig(useNio,
- 0,
- TestUtils.createTempDir()
- .getAbsolutePath(),
- null,
- STORES_XML,
- new Properties()),
- cluster));
- servers.add(ServerTestUtils.startVoldemortServer(socketStoreFactory,
- ServerTestUtils.createServerConfig(useNio,
- 1,
- TestUtils.createTempDir()
- .getAbsolutePath(),
- null,
- STORES_XML,
- new Properties()),
- cluster));
+ boolean useNio = false;
+ int numServers = 2;
+ VoldemortServer[] servers = new VoldemortServer[numServers];
+ Cluster cluster = ServerTestUtils.startVoldemortCluster(numServers,
+ servers,
+ null,
+ socketStoreFactory,
+ useNio,
+ null,
+ STORES_XML,
+ new Properties());
// Initialize versioned puts for basic test
v1 = getVersioned(0, 1, 1, 1, 1, 1);
@@ -87,6 +69,10 @@ public void setUp() throws IOException {
conflict5 = getVersioned(0, 0, 0, 0, 0, 1, 1, 1, 1, 1);
conflict6 = getVersioned(0, 0, 0, 0, 0, 0, 1, 1, 1, 1);
+ Node node = cluster.getNodes().iterator().next();
+ String bootstrapUrl = "tcp://" + node.getHost() + ":" + node.getSocketPort();
+ StoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
+
defaultStoreClient = storeClientFactory.getStoreClient("test");
socketStore = ServerTestUtils.getSocketStore(socketStoreFactory,
"test",
@@ -94,7 +80,6 @@ public void setUp() throws IOException {
RequestFormatType.VOLDEMORT_V1);
}
- @Override
@After
public void tearDown() throws Exception {
socketStore.close();

0 comments on commit de66f98

Please sign in to comment.
Something went wrong with that request. Please try again.