Skip to content

Commit

Permalink
Fixed unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bbansal committed Nov 16, 2009
1 parent d88e17c commit 63a078e
Show file tree
Hide file tree
Showing 12 changed files with 617 additions and 583 deletions.
2 changes: 1 addition & 1 deletion build.xml
Expand Up @@ -282,7 +282,7 @@
<target name="junit" depends="build, buildtest" description="Run junit tests.">
<replace-dir dir="${testreport.dir}" />
<replace-dir dir="${testhtml.dir}" />
<junit printsummary="yes" showoutput="true">
<junit printsummary="yes" showoutput="true" maxmemory="128M">
<classpath refid="test-classpath" />
<formatter type="xml" />
<batchtest fork="yes" todir="${testreport.dir}">
Expand Down
25 changes: 21 additions & 4 deletions test/common/voldemort/ServerTestUtils.java
Expand Up @@ -100,12 +100,25 @@ public static AbstractSocketService getSocketService(boolean useNio,
String storesXml,
String storeName,
int port) {
RequestHandlerFactory factory = new SocketRequestHandlerFactory(getStores(storeName,
clusterXml,
storesXml));
RequestHandlerFactory factory = getSocketRequestHandlerFactory(clusterXml,
storesXml,
getStores(storeName,
clusterXml,
storesXml));
return getSocketService(useNio, factory, port, 5, 10, 10000);
}

public static RequestHandlerFactory getSocketRequestHandlerFactory(String clusterXml,
String storesXml,
StoreRepository storeRepsitory) {

return new SocketRequestHandlerFactory(storeRepsitory,
createMetadataStore(new ClusterMapper().readCluster(new StringReader(clusterXml)),
new StoreDefinitionsMapper().readStoreList(new StringReader(storesXml))),
null,
null);
}

public static AbstractSocketService getSocketService(boolean useNio,
RequestHandlerFactory requestHandlerFactory,
int port,
Expand Down Expand Up @@ -158,7 +171,7 @@ public static Context getJettyServer(String clusterXml,
server.setSendServerVersion(false);
Context context = new Context(server, "/", Context.NO_SESSIONS);

RequestHandler handler = new SocketRequestHandlerFactory(repository).getRequestHandler(requestFormat);
RequestHandler handler = getSocketRequestHandlerFactory(clusterXml, storesXml, repository).getRequestHandler(requestFormat);
context.addServlet(new ServletHolder(new StoreServlet(handler)), "/stores");
server.start();
return context;
Expand Down Expand Up @@ -370,4 +383,8 @@ public static ProtoBuffAdminClientRequestFormat getAdminClient(String bootstrapU
return new ProtoBuffAdminClientRequestFormat(bootstrapURL, config);
}

public static RequestHandlerFactory getSocketRequestHandlerFactory(StoreRepository repository) {
return new SocketRequestHandlerFactory(repository, null, null, null);
}

}
Expand Up @@ -34,7 +34,6 @@
import voldemort.server.StoreRepository;
import voldemort.server.http.HttpService;
import voldemort.server.protocol.RequestHandlerFactory;
import voldemort.server.protocol.SocketRequestHandlerFactory;
import voldemort.store.Store;
import voldemort.store.http.HttpStore;
import voldemort.store.memory.InMemoryStorageEngine;
Expand Down Expand Up @@ -101,7 +100,7 @@ public void doOperation(int i) {
RequestFormatType.VOLDEMORT_V1),
socketPool,
false);
RequestHandlerFactory factory = new SocketRequestHandlerFactory(repository);
RequestHandlerFactory factory = ServerTestUtils.getSocketRequestHandlerFactory(repository);
AbstractSocketService socketService = ServerTestUtils.getSocketService(useNio,
factory,
6666,
Expand Down
11 changes: 9 additions & 2 deletions test/integration/voldemort/socketpool/SimpleSocketPoolTest.java
Expand Up @@ -4,7 +4,6 @@

import junit.framework.TestCase;
import voldemort.client.protocol.RequestFormatType;
import voldemort.server.protocol.RequestHandlerFactory;
import voldemort.server.protocol.SocketRequestHandlerFactory;
import voldemort.server.socket.SocketServer;
import voldemort.socketpool.AbstractSocketPoolTest.TestStats;
Expand Down Expand Up @@ -65,7 +64,15 @@ protected String getRequestKey() throws Exception {

public void testSocketPoolLimitSomeTimeout() throws Exception {
// start a dummy server
SocketServer server = new SocketServer(7666, 50, 50, 1000, new SocketRequestHandlerFactory(null), "test");
SocketServer server = new SocketServer(7666,
50,
50,
1000,
new SocketRequestHandlerFactory(null,
null,
null,
null),
"test");
server.start();

final ResourcePoolConfig config = new ResourcePoolConfig().setTimeout(50,
Expand Down
Expand Up @@ -120,10 +120,6 @@ public void testUpdateAsStreamWithFilter() {

public static class VoldemortFilterImpl implements VoldemortFilter {

public VoldemortFilterImpl() {
System.out.println("instantiating voldemortFilter");
}

public boolean accept(Object key, Versioned<?> value) {
String keyString = ByteUtils.getString(((ByteArray) key).get(), "UTF-8");
if(Integer.parseInt(keyString) % 10 == 3) {
Expand Down
8 changes: 6 additions & 2 deletions test/unit/voldemort/client/AdminServiceBasicTest.java
Expand Up @@ -16,6 +16,7 @@

package voldemort.client;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -28,6 +29,9 @@
import java.util.concurrent.TimeUnit;

import junit.framework.TestCase;

import org.apache.commons.io.FileUtils;

import voldemort.ServerTestUtils;
import voldemort.TestUtils;
import voldemort.client.protocol.admin.AdminClient;
Expand Down Expand Up @@ -83,9 +87,9 @@ public void setUp() throws IOException {

@Override
public void tearDown() throws IOException, InterruptedException {
adminClient.stop();
server.stop();

// TODO : release sockets held by AdminClient
FileUtils.deleteDirectory(new File(server.getVoldemortConfig().getVoldemortHome()));
}

public AdminClient getAdminClient() {
Expand Down
4 changes: 4 additions & 0 deletions test/unit/voldemort/client/AdminServiceFilterTest.java
Expand Up @@ -16,11 +16,14 @@

package voldemort.client;

import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.Map.Entry;

import org.apache.commons.io.FileUtils;

import voldemort.ServerTestUtils;
import voldemort.TestUtils;
import voldemort.client.protocol.admin.AdminClient;
Expand Down Expand Up @@ -66,6 +69,7 @@ public void setUp() throws IOException {
public void tearDown() throws IOException, InterruptedException {
adminClient.stop();
server.stop();
FileUtils.deleteDirectory(new File(server.getVoldemortConfig().getVoldemortHome()));
}

@Override
Expand Down

0 comments on commit 63a078e

Please sign in to comment.