Use tunit to speed testing #32

Merged
merged 2 commits into from Dec 27, 2015
Jump to file or symbol
Failed to load files and symbols.
+77 −24
Diff settings

Always

Just for now

View
@@ -49,10 +49,17 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.8.2</version>
+ <version>4.11</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>io.teknek</groupId>
+ <artifactId>tunit</artifactId>
+ <version>0.0.0</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>io.teknek</groupId>
<artifactId>graphite-reporter</artifactId>
@@ -47,13 +47,15 @@ public void aTest() throws IOException, InterruptedException{
@Test
public void serverIdTest() {
UUID u1, u2;
+ Configuration c ;
{
Server s = TestUtil.aBasicServer(testFolder, 9006);
+ c = s.getConfiguration();
u1 = s.getServerId().getU();
s.shutdown();
}
{
- Server j = TestUtil.aBasicServer(testFolder, 9006);
+ Server j = TestUtil.theSameBasicServer(c);
u2 = j.getServerId().getU();
j.shutdown();
}
@@ -9,6 +9,7 @@
import io.teknek.nibiru.transport.Response;
import java.io.File;
+import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -46,6 +47,15 @@ public static Server aBasicServer(TemporaryFolder testFolder, int port){
s.getMetaDataManager().createOrUpdateStore(DATA_KEYSPACE, BOOKS_KEY_VALUE, TestUtil.STANDARD_KEY_VLUE);
return s;
}
+
+ public static Server theSameBasicServer(Configuration conf){
+ Server s = new Server(conf);
+ s.init();
+ s.getMetaDataManager().createOrUpdateKeyspace(DATA_KEYSPACE, new HashMap<String,Object>());
+ s.getMetaDataManager().createOrUpdateStore(DATA_KEYSPACE, PETS_COLUMN_FAMILY, TestUtil.STANDARD_COLUMN_FAMILY());
+ s.getMetaDataManager().createOrUpdateStore(DATA_KEYSPACE, BOOKS_KEY_VALUE, TestUtil.STANDARD_KEY_VLUE);
+ return s;
+ }
public static Map<String,Object> gossipPropertiesFor127Seed(){
Map<String, Object> clusterProperties = new HashMap<>();
@@ -58,8 +68,19 @@ public static Configuration aBasicConfiguration(TemporaryFolder testFolder){
}
public static Configuration aBasicConfiguration(TemporaryFolder testFolder, int port){
- File tempFolder = testFolder.newFolder("sstable");
- File commitlog = testFolder.newFolder("commitlog");
+ File tempFolder;
+ try {
+
+ tempFolder = testFolder.newFolder("sstable");
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ File commitlog;
+ try {
+ commitlog = testFolder.newFolder("commitlog");
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
Configuration configuration = new Configuration();
configuration.setTransportPort(port);
configuration.setDataDirectory(tempFolder.getPath());
@@ -5,8 +5,9 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
-import junit.framework.Assert;
import io.teknek.nibiru.Configuration;
import io.teknek.nibiru.Server;
@@ -15,7 +16,9 @@
import io.teknek.nibiru.client.MetaDataClient;
import io.teknek.nibiru.engine.DefaultColumnFamily;
import io.teknek.nibiru.metadata.StoreMetaData;
+import io.teknek.tunit.TUnit;
+import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -33,9 +36,10 @@
@Rule
public TemporaryFolder node3Folder = new TemporaryFolder();
+ @SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void letTwoNodesDiscoverEachOther() throws InterruptedException, ClientException{
- Server [] s = new Server[3];
+ final Server [] s = new Server[3];
{
Configuration conf = TestUtil.aBasicConfiguration(node1Folder);
Map<String,Object> clusterProperties = new HashMap<>();
@@ -63,14 +67,20 @@ public void letTwoNodesDiscoverEachOther() throws InterruptedException, ClientEx
for (Server server : s){
server.init();
}
- Thread.sleep(11000);
+ TUnit.assertThat( new Callable(){
+ public Object call() throws Exception {
+ return s[2].getClusterMembership().getLiveMembers().size();
+ }}).afterWaitingAtMost(11, TimeUnit.SECONDS).isEqualTo(2);
Assert.assertEquals(2 , s[2].getClusterMembership().getLiveMembers().size());
Assert.assertEquals("127.0.0.1", s[2].getClusterMembership().getLiveMembers().get(0).getHost());
MetaDataClient c = new MetaDataClient("127.0.0.1", s[1].getConfiguration().getTransportPort(), 20000, 20000);
c.createOrUpdateKeyspace("abc", new HashMap<String,Object>(), true);
- Thread.sleep(1000);
- for (Server server : s){
- Assert.assertNotNull(server.getKeyspaces().get("abc"));
+ for (final Server server : s) {
+ TUnit.assertThat(new Callable() {
+ public Object call() throws Exception {
+ return server.getKeyspaces().get("abc") != null;
+ }
+ }).afterWaitingAtMost(1000, TimeUnit.MILLISECONDS).isEqualTo(true);
}
Map<String,Object> stuff = new HashMap<String,Object>();
stuff.put(StoreMetaData.IMPLEMENTING_CLASS, DefaultColumnFamily.class.getName());
@@ -55,8 +55,18 @@ public void aTest() throws IOException{
}
public static Configuration getBasicConfiguration(TemporaryFolder testFolder){
- File tempFolder = testFolder.newFolder("sstable");
- File commitlog = testFolder.newFolder("commitlog");
+ File tempFolder;
+ try {
+ tempFolder = testFolder.newFolder("sstable");
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ File commitlog;
+ try {
+ commitlog = testFolder.newFolder("commitlog");
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
Configuration configuration = new Configuration();
configuration.setDataDirectory(tempFolder.getPath());
configuration.setCommitlogDirectory(commitlog.getPath());
@@ -15,14 +15,16 @@
import io.teknek.nibiru.metadata.StoreMetaData;
import io.teknek.nibiru.router.TokenRouter;
import io.teknek.nibiru.transport.Response;
+import io.teknek.tunit.TUnit;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
+import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
-import junit.framework.Assert;
-import org.junit.Ignore;
+import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -38,7 +40,7 @@
@Test
public void test() throws ClientException, InterruptedException{
- Server[] servers = new Server[2];
+ final Server[] servers = new Server[2];
TemporaryFolder [] tempFolders = { node1Folder, node2Folder};
Configuration [] cs = new Configuration[2];
for (int i = 0; i < cs.length; i++) {
@@ -49,7 +51,7 @@ public void test() throws ClientException, InterruptedException{
}
servers[0].init();
- MetaDataClient metaClient = new MetaDataClient(servers[0].getConfiguration().getTransportHost(), servers[0]
+ final MetaDataClient metaClient = new MetaDataClient(servers[0].getConfiguration().getTransportHost(), servers[0]
.getConfiguration().getTransportPort());
createKeyspaceInformation(metaClient, servers);
Assert.assertEquals(servers[0].getClusterMembership().getLiveMembers().size(), 0);//We do not count ourselves
@@ -63,22 +65,23 @@ public void test() throws ClientException, InterruptedException{
for (int k = 0; k < 10; k++) {
session.put(k+"", k+"", k+"", 1);
}
-
servers[1].init();
- Thread.sleep(10000);
- Assert.assertEquals(servers[0].getClusterMembership().getLiveMembers().size(), 1);
+ TUnit.assertThat( new Callable(){
+ public Object call() throws Exception {
+ return servers[0].getClusterMembership().getLiveMembers().size();
+ }}).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo(1);
servers[1].join("abc", "127.0.0.1", "5");
Thread.sleep(1000);
Assert.assertEquals(servers[1].getServerId().getU().toString(),
servers[0].getCoordinator().getSponsorCoordinator().getProtege().getDestinationId());
-
insertDataOverClient(session);
assertDataIsDistributed(servers);
-
- Thread.sleep(5000);
- Map<String,String> keyspaceMembers = (Map<String, String>) metaClient.getKeyspaceMetadata("abc").get(TokenRouter.TOKEN_MAP_KEY);
- Assert.assertEquals(2, keyspaceMembers.size());
+ TUnit.assertThat( new Callable(){
+ public Object call() throws Exception {
+ Map<String,String> keyspaceMembers = (Map<String, String>) metaClient.getKeyspaceMetadata("abc").get(TokenRouter.TOKEN_MAP_KEY);
+ return keyspaceMembers.size();
+ }}).afterWaitingAtMost(5, TimeUnit.SECONDS).isEqualTo(2);
for (int i = 0; i < cs.length; i++) {
servers[i].shutdown();