Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions driver/src/main/java/oracle/nosql/driver/ops/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ public void copyTo(Request other) {
other.setCheckRequestSize(this.checkRequestSize);
other.setCompartmentInternal(this.compartment);
other.setTableNameInternal(this.tableName);
other.setNamespaceInternal(this.namespace);
other.setStartNanos(this.startNanos);
other.setRetryStats(this.retryStats);
other.setReadRateLimiter(this.readRateLimiter);
Expand Down
157 changes: 135 additions & 22 deletions driver/src/test/java/oracle/nosql/driver/OnPremiseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,26 +453,119 @@ public void testNamespaces()
/*
* Note: tables will be dropped by a cascading drop of the namespace
*/
final String parentName = "parent";
final String childName = "parent.child";
final String nsParentName = "myns:parent";
final String nsChildName = "myns:parent.child";

final String parentName = "myns:parent";
final String childName = "myns:parent.child";
final int numParent = 30;
final int numChild = 40;

((NoSQLHandleImpl)handle).setDefaultNamespace("myns");

doSysOp(handle, "create namespace myns");

/* parent in myns */
TableRequest treq = new TableRequest().setStatement(
"create table parent(id integer, primary key(id))");
"create table myns:parent(id integer, primary key(id))");
TableResult tres = handle.tableRequest(treq);
tres.waitForCompletion(handle, 100000, 1000);

/* child in myns */
treq = new TableRequest().setStatement(
"create table parent.child(cid integer, name string, " +
"create table myns:parent.child(cid integer, name string, " +
"primary key(cid))");
tres = handle.tableRequest(treq);
tres.waitForCompletion(handle, 100000, 1000);

/* put data in both tables */
PutRequest preq = new PutRequest();
MapValue value = new MapValue();
for (int i = 0; i < numParent; i++) {
value.put("name", "myname"); // ignored in parent
value.put("id", i);
preq.setTableName(parentName).setValue(value);
PutResult pres = handle.put(preq);
assertNotNull("Parent put failed", pres.getVersion());
for (int j = 0; j < numChild; j++) {
value.put("cid", j); // ignored in parent
preq.setTableName(childName).setValue(value);
pres = handle.put(preq);
assertNotNull("Child put failed", pres.getVersion());
assertNoUnits(pres);
}
}

/* get parent */
GetRequest getReq = new GetRequest().setTableName(parentName)
.setKey(new MapValue().put("id", 1));
GetResult getRes = handle.get(getReq);
assertNotNull(getRes.getValue());

/* get child */
getReq = new GetRequest().setTableName(childName)
.setKey(new MapValue().put("id", 1).put("cid", 1));
getRes = handle.get(getReq);
assertNotNull(getRes.getValue());
assertNoUnits(getRes);

try {
/* query parent */
String query = "select * from " + parentName;
List<MapValue> res = doQuery(handle, query);
assertEquals(numParent, res.size());

/* query child */
query = "select * from " + childName;
res = doQuery(handle, query);
assertEquals(numParent * numChild, res.size());

/* prepared query on child */
res = doPreparedQuery(handle, query);
assertEquals(numParent * numChild, res.size());
} catch (RequestTimeoutException rte) {
/*
if (!(rte.getCause() instanceof SystemException)) {
throw rte;
}
*/
/* ignore this exception for 19 for now; known bug */
}

/* test ListTables with namespace */
ListTablesRequest listTables =
new ListTablesRequest().setNamespace("myns");
ListTablesResult lres = handle.listTables(listTables);
assertEquals(2, lres.getTables().length);
}

@Test
public void testDefaultNamespaces()
throws Exception {

/* this only works with versions of KV with default namespace support */
assumeKVVersion("testDefaultNamespaces", 22, 3, 32);

/*
* Note: tables will be dropped by a cascading drop of the namespace
*/
final String parentName = "parent";
final String childName = "parent.child";
final String nsParentName = "mydns:parent";
final String nsChildName = "mydns:parent.child";
final int numParent = 30;
final int numChild = 40;

((NoSQLHandleImpl)handle).setDefaultNamespace("mydns");

doSysOp(handle, "create namespace mydns");

/* parent in mydns */
TableRequest treq = new TableRequest().setStatement(
"create table parent(sid integer, id integer, name string, " +
"salary long, primary key(SHARD(sid), id))");
TableResult tres = handle.tableRequest(treq);
tres.waitForCompletion(handle, 100000, 1000);

/* child in mydns */
treq = new TableRequest().setStatement(
"create table parent.child(cid integer, cname string, " +
"primary key(cid))");
tres = handle.tableRequest(treq);
tres.waitForCompletion(handle, 100000, 1000);
Expand All @@ -486,7 +579,7 @@ public void testNamespaces()
assertTrue(lres.getTables().length > 2);

/* test ListTables with explicit namespace */
listTables = new ListTablesRequest().setNamespace("myns");
listTables = new ListTablesRequest().setNamespace("mydns");
lres = handle.listTables(listTables);
assertEquals(2, lres.getTables().length);

Expand All @@ -499,13 +592,16 @@ public void testNamespaces()
PutRequest preq = new PutRequest();
MapValue value = new MapValue();
for (int i = 0; i < numParent; i++) {
value.put("name", "myname"); // ignored in parent
value.put("name", "pname");
value.put("id", i);
value.put("sid", i);
value.put("salary", i*1000);
preq.setTableName(parentName).setValue(value);
PutResult pres = handle.put(preq);
assertNotNull("Parent put failed", pres.getVersion());
for (int j = 0; j < numChild; j++) {
value.put("cid", j); // ignored in parent
value.put("cid", j);
value.put("cname", "cname" + j);
preq.setTableName(childName).setValue(value);
pres = handle.put(preq);
assertNotNull("Child put failed", pres.getVersion());
Expand All @@ -515,13 +611,13 @@ public void testNamespaces()

/* get parent */
GetRequest getReq = new GetRequest().setTableName(parentName)
.setKey(new MapValue().put("id", 1));
.setKey(new MapValue().put("id", 1).put("sid", 1));
GetResult getRes = handle.get(getReq);
assertNotNull(getRes.getValue());

/* get child */
getReq = new GetRequest().setTableName(childName)
.setKey(new MapValue().put("id", 1).put("cid", 1));
.setKey(new MapValue().put("id", 1).put("sid", 1).put("cid", 1));
getRes = handle.get(getReq);
assertNotNull(getRes.getValue());
assertNoUnits(getRes);
Expand Down Expand Up @@ -564,7 +660,7 @@ public void testNamespaces()

/* this should fail */
getReq = new GetRequest().setTableName(parentName)
.setKey(new MapValue().put("id", 1));
.setKey(new MapValue().put("id", 1).put("sid", 1));
try {
getRes = handle.get(getReq);
fail("Get should have failed");
Expand All @@ -574,25 +670,42 @@ public void testNamespaces()

/* This should pass */
getReq = new GetRequest().setTableName(parentName)
.setNamespace("myns")
.setKey(new MapValue().put("id", 1));
.setNamespace("mydns")
.setKey(new MapValue().put("id", 1).put("sid", 1));
getRes = handle.get(getReq);
assertNotNull(getRes.getValue());

/* This should pass */
((NoSQLHandleImpl)handle).setDefaultNamespace("invalid");
getReq = new GetRequest().setTableName(parentName)
.setNamespace("myns")
.setKey(new MapValue().put("id", 1));
.setNamespace("mydns")
.setKey(new MapValue().put("id", 1).put("sid", 1));
getRes = handle.get(getReq);
assertNotNull(getRes.getValue());


/* test complex query (exercises internal request copying) */
String query = "select sid, count(*) as cnt, sum(salary) as sum " +
"from " + parentName + " group by sid";
/* this should pass */
List<MapValue> res = doQuery(handle, query, "mydns");
assertEquals(numParent, res.size());

/* this should fail */
try {
res = doQuery(handle, query, "invalid");
fail("query should have failed");
} catch (TableNotFoundException e) {
// expected
}


/* verify table name overrides request namespace */

/* this should fail */
getReq = new GetRequest().setTableName(parentName)
.setNamespace("invalid")
.setKey(new MapValue().put("id", 1));
.setKey(new MapValue().put("id", 1).put("sid", 1));
try {
getRes = handle.get(getReq);
fail("Get should have failed");
Expand All @@ -603,19 +716,19 @@ public void testNamespaces()
/* This should pass */
getReq = new GetRequest().setTableName(nsParentName)
.setNamespace("invalid")
.setKey(new MapValue().put("id", 1));
.setKey(new MapValue().put("id", 1).put("sid", 1));
getRes = handle.get(getReq);
assertNotNull(getRes.getValue());

/* drop table with namespace in request */
treq = new TableRequest()
.setStatement("drop table parent.child")
.setNamespace("myns");
.setNamespace("mydns");
tres = handle.tableRequest(treq);
tres.waitForCompletion(handle, 100000, 1000);

/* drop namespace - use cascade to remove tables */
doSysOp(handle, "drop namespace myns cascade");
doSysOp(handle, "drop namespace mydns cascade");
}

/**
Expand Down
9 changes: 9 additions & 0 deletions driver/src/test/java/oracle/nosql/driver/ProxyTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,17 @@ static private ArrayValue createLargeStringArray(int size) {
}

protected static List<MapValue> doQuery(NoSQLHandle qHandle, String query) {
return doQuery(qHandle, query, null);
}

protected static List<MapValue> doQuery(NoSQLHandle qHandle,
String query,
String namespace) {
try( QueryRequest queryRequest = new QueryRequest()) {
queryRequest.setStatement(query);
if (namespace != null) {
queryRequest.setNamespace(namespace);
}
List<MapValue> results = new ArrayList<MapValue>();

do {
Expand Down