Skip to content

Commit

Permalink
More tests...
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Mast committed Feb 25, 2015
1 parent 0da09df commit 87d727b
Show file tree
Hide file tree
Showing 13 changed files with 296 additions and 40 deletions.
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ java_wrappers += test/sh/bindings.java.DataTypeSetString.sh
java_wrappers += test/sh/bindings.java.DataTypeString.sh
java_wrappers += test/sh/bindings.java.LengthString.sh
java_wrappers += test/sh/bindings.java.Microtransactions.sh
java_wrappers += test/sh/bindings.java.MultitypeMicrotransactions.sh
java_wrappers += test/sh/bindings.java.MultiAttribute.sh
java_wrappers += test/sh/bindings.java.RangeSearchInt.sh
java_wrappers += test/sh/bindings.java.RangeSearchString.sh
Expand Down Expand Up @@ -1062,6 +1063,7 @@ EXTRA_DIST += test/java/DataTypeSetString.java
EXTRA_DIST += test/java/DataTypeString.java
EXTRA_DIST += test/java/LengthString.java
EXTRA_DIST += test/java/Microtransactions.java
EXTRA_DIST += test/java/MultitypeMicrotransactions.java
EXTRA_DIST += test/java/MultiAttribute.java
EXTRA_DIST += test/java/RangeSearchInt.java
EXTRA_DIST += test/java/RangeSearchString.java
Expand Down
6 changes: 6 additions & 0 deletions bindings/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ def generate_client_doc():
private static native void initialize();
private static native void terminate();
public Long group_commit(Map<String,Object> checks) throws HyperDexClientException {
return (Long) async_group_commit(checks).waitForIt();
}
public native Deferred async_group_commit(Map<String,Object> checks) throws HyperDexClientException;
public Boolean commit(String key) throws HyperDexClientException {
return (Boolean) async_commit(key).waitForIt();
}
Expand Down
11 changes: 11 additions & 0 deletions bindings/java/client-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ hyperdex_java_client_convert_key(JNIEnv* env, jobject client,
const char** key,
size_t* key_sz);

int
hyperdex_java_client_convert_predicates(JNIEnv* env, jobject client,
struct hyperdex_ds_arena* arena,
jobject x,
const struct hyperdex_client_attribute_check** _checks,
size_t* _checks_sz);

int
hyperdex_java_client_throw_exception(JNIEnv* env,
enum hyperdex_client_returncode _rc,
Expand All @@ -72,4 +79,8 @@ struct hyperdex_java_client_deferred
jobject (*encode_return)(JNIEnv* env, jobject obj, struct hyperdex_java_client_deferred* d);
};

jobject
hyperdex_java_client_deferred_encode_status_count(JNIEnv* env, jobject obj, struct hyperdex_java_client_deferred* d);


#endif
6 changes: 6 additions & 0 deletions bindings/java/org/hyperdex/client/Microtransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ protected Microtransaction(Client client, String space)
private static native void initialize();
private static native void terminate();

public Long group_commit(Map<String,Object> checks) throws HyperDexClientException {
return (Long) async_group_commit(checks).waitForIt();
}

public native Deferred async_group_commit(Map<String,Object> checks) throws HyperDexClientException;

public Boolean commit(String key) throws HyperDexClientException {
return (Boolean) async_commit(key).waitForIt();
}
Expand Down
4 changes: 2 additions & 2 deletions bindings/java/org_hyperdex_client_Client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ hyperdex_java_client_convert_predicate(JNIEnv* env,
}
}

static int
int
hyperdex_java_client_convert_predicates(JNIEnv* env, jobject client,
struct hyperdex_ds_arena* arena,
jobject x,
Expand Down Expand Up @@ -1909,7 +1909,7 @@ hyperdex_java_client_deferred_encode_status_attributes(JNIEnv* env, jobject obj,
}
}

static jobject
jobject
hyperdex_java_client_deferred_encode_status_count(JNIEnv* env, jobject obj, struct hyperdex_java_client_deferred* d)
{
jobject ret;
Expand Down
29 changes: 29 additions & 0 deletions bindings/java/org_hyperdex_client_Microtransaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,35 @@ hyperdex_java_uxact_deferred_encode_status(JNIEnv* env, jobject obj, struct hype
}
}


JNIEXPORT HYPERDEX_API jobject JNICALL
Java_org_hyperdex_client_Microtransaction_async_1group_1commit(JNIEnv* env, jobject uxact, jstring checks)
{
const struct hyperdex_client_attribute_check *chks;
size_t chks_sz;
struct hyperdex_client* client_ptr = hyperdex_uxact_get_client_ptr(env, uxact);
struct hyperdex_client_microtransaction *uxact_ptr = hyperdex_uxact_get_uxact_ptr(env, uxact);
jobject client = hyperdex_uxact_get_client(env, uxact);
jobject op = (*env)->NewObject(env, _deferred, _deferred_init, client);
struct hyperdex_java_client_deferred* o = hyperdex_uxact_get_deferred_ptr(env, uxact);
ERROR_CHECK(0);

hyperdex_java_client_convert_predicates(env, client, o->arena, checks, &chks, &chks_sz);
o->encode_return = hyperdex_java_client_deferred_encode_status_count;
o->reqid = hyperdex_client_uxact_group_commit(client_ptr, uxact_ptr, chks, chks_sz, &o->count);

(*env)->SetLongField(env, op, _deferred_ptr, (long)o);

if (o->reqid < 0)
{
hyperdex_java_client_throw_exception(env, o->status, hyperdex_client_error_message(client_ptr));
return NULL;
}
(*env)->CallObjectMethod(env, client, _client_add_op, o->reqid, op);
ERROR_CHECK(0);
return op;
}

JNIEXPORT HYPERDEX_API jobject JNICALL
Java_org_hyperdex_client_Microtransaction_async_1commit(JNIEnv* env, jobject uxact, jstring key)
{
Expand Down
8 changes: 8 additions & 0 deletions bindings/java/org_hyperdex_client_Microtransaction.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions test/java/DataTypeDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@ public void setUpHyperdexClient() throws Exception {

@After
public void destroyHyperdexClient() throws HyperDexClientException {
Map<String, Object> match_all = new HashMap<String, Object>();
Map<String, Object> match_all = new HashMap<>();
c.group_del("kv", match_all);
c = null;
}

@Test
public void insertEmptyValue() throws HyperDexClientException {
Map<String, Object> attrs = new HashMap<String, Object>();
Map<String, Object> attrs = new HashMap<>();

Boolean res = c.put("kv", "k", attrs);
assertTrue(res);

Map<String, Object> get = c.get("kv", "k");
Map<String, Object> expected = new HashMap<String, Object>();
Map<String, Object> expected = new HashMap<>();
expected.put("v", new Document("{}"));
assertEquals(expected, get);
}

@Test
public void insertEmptyDocument() throws HyperDexClientException {
Map<String, Object> attrs = new HashMap<String, Object>();
Map<String, Object> attrs = new HashMap<>();
attrs.put("v", new Document("{}"));

Boolean res = c.put("kv", "k", attrs);
assertTrue(res);

Map<String, Object> get = c.get("kv", "k");
Map<String, Object> expected = new HashMap<String, Object>();
Map<String, Object> expected = new HashMap<>();
expected.put("v", new Document("{}"));

assertEquals(expected, get);
Expand All @@ -69,17 +69,17 @@ public void insertNestedDocument() throws HyperDexClientException {

@Test
public void setField() throws HyperDexClientException {
Map<String, Object> attrs = new HashMap<String, Object>();
Map<String, Object> attrs = new HashMap<>();
attrs.put("v", new Document("{}"));
c.put("kv", "k", attrs);

Map<String, Object> attrs2 = new HashMap<String, Object>();
Map<String, Object> attrs2 = new HashMap<>();
attrs2.put("v.a", "xyz");
Boolean res = c.put("kv", "k", attrs2);
assertTrue(res);

Map<String, Object> get = c.get("kv", "k");
Map<String, Object> expected = new HashMap<String, Object>();
Map<String, Object> expected = new HashMap<>();
assert(get.get("v") instanceof Document);
expected.put("v", new Document("{\"a\":\"xyz\"}"));
assertEquals(expected, get);
Expand Down
40 changes: 30 additions & 10 deletions test/java/DataTypeInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public void setUpHyperdexClient() throws Exception {

@After
public void destroyHyperdexClient() throws HyperDexClientException {
Map<String, Object> match_all = new HashMap<String, Object>();
Map<String, Object> match_all = new HashMap<>();
c.group_del("kv", match_all);
c = null;
}

@Test
public void testInsertEmpty() throws HyperDexClientException {
Map<String, Object> attrs = new HashMap<String, Object>();
Map<String, Object> attrs = new HashMap<>();
Boolean res = c.put("kv", "k", attrs);
assertTrue(res);

Expand All @@ -47,9 +47,16 @@ public void testInsertEmpty() throws HyperDexClientException {
assertEquals(expected, get);
}

@Test(expected = HyperDexClientException.class)
public void testWrongTypeThrowsException() throws HyperDexClientException {
Map<String, Object> attrs = new HashMap<>();
attrs.put("v", "Not-an-Int");
c.put("kv", "k", attrs);
}

@Test
public void testInsertOne() throws HyperDexClientException {
Map<String, Object> attrs = new HashMap<String, Object>();
Map<String, Object> attrs = new HashMap<>();
attrs.put("v", 1L);

Boolean res = c.put("kv", "k", attrs);
Expand All @@ -64,7 +71,7 @@ public void testInsertOne() throws HyperDexClientException {

@Test
public void testInsertZero() throws HyperDexClientException {
Map<String, Object> attrs = new HashMap<String, Object>();
Map<String, Object> attrs = new HashMap<>();
attrs.put("v", 0L);

Boolean res = c.put("kv", "k", attrs);
Expand All @@ -76,44 +83,57 @@ public void testInsertZero() throws HyperDexClientException {

assertEquals(expected, get);
}

@Test
public void testDivideByZeroNotAllowed() throws HyperDexClientException {
Map<String, Object> attrs = new HashMap<>();
attrs.put("v", 1L);
c.put("kv", "k", attrs);

Map<String, Object> args = new HashMap<>();
args.put("v", 0L);

Boolean res = c.atomic_div("kv", "k", args);
assertFalse(args);
}

@Test
public void testNegativeValue() throws HyperDexClientException {
Map<String, Object> attrs = new HashMap<String, Object>();
Map<String, Object> attrs = new HashMap<>();
attrs.put("v", -1L);
Boolean res = c.put("kv", "k", attrs);
assertTrue(res);

Map<String, Object> get = c.get("kv", "k");
Map<String, Object> expected = new HashMap<String, Object>();
Map<String, Object> expected = new HashMap<>();
expected.put("v", -1L);

assertEquals(expected, get);
}

@Test
public void testInsertHugePositiveValue() throws HyperDexClientException {
Map<String, Object> attrs = new HashMap<String, Object>();
Map<String, Object> attrs = new HashMap<>();
attrs.put("v", 9223372036854775807L);
Boolean res = c.put("kv", "k", attrs);
assertTrue(res);

Map<String, Object> get = c.get("kv", "k");
Map<String, Object> expected = new HashMap<String, Object>();
Map<String, Object> expected = new HashMap<>();
expected.put("v", 9223372036854775807L);

assertEquals(expected, get);
}

@Test
public void testInsertHugeNegativeValue() throws HyperDexClientException {
Map<String, Object> attrs = new HashMap<String, Object>();
Map<String, Object> attrs = new HashMap<>();
attrs.put("v", -9223372036854775807L);
Boolean res = c.put("kv", "k", attrs);
assertTrue(res);

Map<String, Object> get = c.get("kv", "k");
Map<String, Object> expected = new HashMap<String, Object>();
Map<String, Object> expected = new HashMap<>();
expected.put("v", -9223372036854775807L);

assertEquals(expected, get);
Expand Down
19 changes: 13 additions & 6 deletions test/java/DataTypeString.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public void setUpHyperdexClient() throws Exception {

@After
public void destroyHyperdexClient() throws HyperDexClientException {
Map<String, Object> match_all = new HashMap<String, Object>();
Map<String, Object> match_all = new HashMap<>();
c.group_del("kv", match_all);
c = null;
}

@Test
public void insertEmptyValue() throws HyperDexClientException {
Map<String, Object> attrs = new HashMap<String, Object>();
Map<String, Object> attrs = new HashMap<>();

Boolean res = c.put("kv", "k", attrs);
assertTrue(res);
Expand All @@ -47,30 +47,37 @@ public void insertEmptyValue() throws HyperDexClientException {
assertEquals(get, expected);
}

@Test(expected = HyperDexClientException.class)
public void testWrongTypeThrowsException() throws HyperDexClientException {
Map<String, Object> attrs = new HashMap<>();
attrs.put("v", 42);
c.put("kv", "k", attrs);
}

@Test
public void insertString() throws HyperDexClientException {
Map<String, Object> attrs = new HashMap<String, Object>();
Map<String, Object> attrs = new HashMap<>();
attrs.put("v", "xxx");

Boolean res = c.put("kv", "k", attrs);
assertTrue(res);

Map<String, Object> get = c.get("kv", "k");
Map<String, Object> expected = new HashMap<String, Object>();
Map<String, Object> expected = new HashMap<>();
expected.put("v", "xxx");
assertEquals(get, expected);
}

@Test
public void insertBytes() throws HyperDexClientException {
Map<String, Object> attrs = new HashMap<String, Object>();
Map<String, Object> attrs = new HashMap<>();
byte[] bytes = {(byte) 0xde, (byte) 0xad, (byte) 0xbe, (byte) 0xef};
attrs.put("v", new ByteString(bytes));
Boolean res = c.put("kv", "k", attrs);
assertTrue(res);

Map<String, Object> get = c.get("kv", "k");
Map<String, Object> expected = new HashMap<String, Object>();
Map<String, Object> expected = new HashMap<>();
expected.put("v", new ByteString(bytes));
assertEquals(get, expected);
}
Expand Down
Loading

0 comments on commit 87d727b

Please sign in to comment.