Skip to content

Commit

Permalink
added testng.xml, changed previous test classes to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reikje committed Jan 10, 2011
1 parent 3a6d4d8 commit 9e857d9
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 65 deletions.
Expand Up @@ -7,76 +7,75 @@
import java.io.IOException;

import com.google.protobuf.ByteString;
import org.testng.annotations.Test;

public class BatchPushLotsOfData {
@Test(groups = "db", dependsOnMethods = "testIsRunning", sequential = true)
public class BatchPushLotsOfDataTest {

public void testBatchPushingLotsofData() throws InterruptedException, IOException {
final RiakClient riak = new RiakClient("127.0.0.1");



public static void main(String[] args) throws IOException, InterruptedException {

final RiakClient riak = new RiakClient("127.0.0.1");

long before = System.currentTimeMillis();

Thread t1 = new Thread() {
public void run() {
try {
insert_batch(riak, 1);
} catch (IOException e) {
e.printStackTrace();
}
}
};
};

Thread t2 = new Thread() {
public void run() {
try {
insert_batch(riak, 2);
} catch (IOException e) {
e.printStackTrace();
}
}
};
};

t1.start(); t2.start();

t1.join(); t2.join();


long after = System.currentTimeMillis();

System.out.println("TOTAL TIME: "+(1.0*(after-before)/1000.0)+"s");
}
}

private static void insert_batch(RiakClient riak, int prefix) throws IOException {
byte[] val = new byte[419];
ByteString value = ByteString.copyFrom(val);


for (int i = 0; i < 100; i++) {

long before2 = System.currentTimeMillis();

String cpr = "" + (prefix*1000000000+i);
ByteString cpr_key = ByteString.copyFromUtf8(cpr);

RiakObject[] many = new RiakObject[1000];

for (int rid = 0; rid < 1000; rid++) {

ByteString rid_key = ByteString.copyFromUtf8("" + (200000+i));

many[rid] = new RiakObject(cpr_key, rid_key, value);

}

riak.store(many, null);

long after2 = System.currentTimeMillis();

System.out.println(prefix+": "+i+" x 1000 INSERTS: "+(after2-before2)+"ms");

}
}

}
Expand Up @@ -7,37 +7,34 @@
import java.util.Map;

import com.google.protobuf.ByteString;
import org.testng.annotations.Test;

public class ListAllContents {
@Test(groups = "db", dependsOnMethods = "testIsRunning", sequential = true)
public class ListAllContentsTest {

public static void main(String[] args) throws IOException {

public void testListingAllContents() throws IOException {
RiakClient client = new RiakClient("127.0.0.1");
Map<String, String> si = client.getServerInfo();

System.out.println("connected to: "+si);

ByteString[] buckets = client.listBuckets();
for (ByteString bucket : buckets) {

System.out.println("=bucket "+bucket.toStringUtf8());

KeySource keys = client.listKeys(bucket);
for (ByteString key : keys) {

System.out.println("==key "+key.toStringUtf8());

RiakObject[] ros = client.fetch(bucket, key);
for (RiakObject ro : ros) {

System.out.println("==="+ro.toString());

}
}
}


}


}
}
Expand Up @@ -7,48 +7,46 @@
import java.io.IOException;

import com.google.protobuf.ByteString;
import org.testng.annotations.Test;

public class PushLotsOfData {
@Test(groups = "db", dependsOnMethods = "testIsRunning", sequential = true)
public class PushLotsOfDataTest {



public static void main(String[] args) throws IOException {

public void testPushingLotsOfData() throws IOException {
RiakClient riak = new RiakClient("127.0.0.1", RiakConnection.DEFAULT_RIAK_PB_PORT);

long before = System.currentTimeMillis();


byte[] val = new byte[419];
ByteString value = ByteString.copyFrom(val);


for (int i = 0; i < 100; i++) {

long before2 = System.currentTimeMillis();

String cpr = "" + (1000000000+i);
ByteString cpr_key = ByteString.copyFromUtf8(cpr);

for (int rid = 0; rid < 1000; rid++) {

ByteString rid_key = ByteString.copyFromUtf8("" + (200000+i));

RiakObject ro = new RiakObject(cpr_key, rid_key, value);
riak.store(ro);

}

long after2 = System.currentTimeMillis();

System.out.println(""+i+" x 1000 INSERTS: "+(after2-before2)+"ms");

}


long after = System.currentTimeMillis();

System.out.println("TOTAL TIME: "+(1.0*(after-before)/1000.0)+"s");
}

}
}
28 changes: 28 additions & 0 deletions src/test/java/com/trifork/riak/RiakRunningTest.java
@@ -0,0 +1,28 @@
package com.trifork.riak;

import org.testng.annotations.Test;

import java.io.IOException;

import static org.testng.FileAssert.fail;

/**
* Verifies that Riak is running.
*
* @author reiks, Jan 5, 2011
*/
@Test(groups = "db", sequential = true)
public class RiakRunningTest {

public void testIsRunning() {
try
{
RiakClient client = new RiakClient("127.0.0.1");
client.ping();
}
catch (IOException e)
{
fail("Unable to connect to Riak (host: 127.0.0.1, port: " + RiakConnection.DEFAULT_RIAK_PB_PORT + ")");
}
}
}
16 changes: 16 additions & 0 deletions src/test/resources/testng.xml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="riak-java-pb-client-suite" verbose="4">
<test name="run-all">
<groups>
<run>
<include name="unit" />
<exclude name="db" />
</run>
</groups>
<packages>
<package name="com.trifork.riak.*"/>
</packages>
</test>
</suite>

0 comments on commit 9e857d9

Please sign in to comment.