address code review comments and add more places for test code
This commit is contained in:
parent
c0aa361885
commit
9e79ff49a6
|
@ -38,6 +38,12 @@ The tenant API introduces some new operations:
|
||||||
|
|
||||||
Unsets the active tenant.
|
Unsets the active tenant.
|
||||||
|
|
||||||
|
#### TENANT_LIST
|
||||||
|
|
||||||
|
Pops the top 3 items off of the stack as BEGIN, END, & LIMIT. Returns list
|
||||||
|
of tenants contained in the range BEGIN to END, numbering LIMIT at most.
|
||||||
|
May optionally push a future onto the stack.
|
||||||
|
|
||||||
Updates to Existing Instructions
|
Updates to Existing Instructions
|
||||||
--------------------------------
|
--------------------------------
|
||||||
|
|
||||||
|
|
|
@ -600,6 +600,10 @@ class ApiTest(Test):
|
||||||
instructions.append(op)
|
instructions.append(op)
|
||||||
elif op == 'TENANT_CLEAR_ACTIVE':
|
elif op == 'TENANT_CLEAR_ACTIVE':
|
||||||
instructions.append(op)
|
instructions.append(op)
|
||||||
|
elif op == 'TENANT_LIST':
|
||||||
|
instructions.push_args(b'', b'\xff', 10)
|
||||||
|
instructions.append(op)
|
||||||
|
self.add_strings(1)
|
||||||
else:
|
else:
|
||||||
assert False, 'Unknown operation: ' + op
|
assert False, 'Unknown operation: ' + op
|
||||||
|
|
||||||
|
|
|
@ -282,7 +282,7 @@ public class TenantManagement {
|
||||||
@Override
|
@Override
|
||||||
public KeyValue next() {
|
public KeyValue next() {
|
||||||
KeyValue kv = iter.next();
|
KeyValue kv = iter.next();
|
||||||
byte[] tenant = ByteArrayUtil.replace(kv.getKey(), 0, kv.getKey().length, TENANT_MAP_PREFIX, null);
|
byte[] tenant = Arrays.copyOfRange(kv.getKey(), TENANT_MAP_PREFIX.length, kv.getKey().length);
|
||||||
byte[] value = kv.getValue();
|
byte[] value = kv.getValue();
|
||||||
|
|
||||||
KeyValue result = new KeyValue(tenant, value);
|
KeyValue result = new KeyValue(tenant, value);
|
||||||
|
|
|
@ -91,7 +91,7 @@ class FDBTenantList(object):
|
||||||
def to_list(self):
|
def to_list(self):
|
||||||
return list(self.__iter__())
|
return list(self.__iter__())
|
||||||
|
|
||||||
def __iter__(self, mode=None):
|
def __iter__(self):
|
||||||
while True:
|
while True:
|
||||||
result = self._iter.__next__()
|
result = self._iter.__next__()
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,16 @@ def test_tenant_operations(db):
|
||||||
fdb.tenant_management.create_tenant(db, b'tenant2')
|
fdb.tenant_management.create_tenant(db, b'tenant2')
|
||||||
|
|
||||||
tenant_list = fdb.tenant_management.list_tenants(db, b'a', b'z', 10).to_list()
|
tenant_list = fdb.tenant_management.list_tenants(db, b'a', b'z', 10).to_list()
|
||||||
assert tenant_list[0] == b'tenant1'
|
assert tenant_list[0].key == b'tenant1'
|
||||||
assert tenant_list[1] == b'tenant2'
|
assert tenant_list[1].key == b'tenant2'
|
||||||
|
|
||||||
|
t1_entry = tenant_list[0].value
|
||||||
|
t1_json = json.loads(t1_entry)
|
||||||
|
p1 = t1_json['prefix'].encode('utf8')
|
||||||
|
|
||||||
|
t2_entry = tenant_list[1].value
|
||||||
|
t2_json = json.loads(t2_entry)
|
||||||
|
p2 = t2_json['prefix'].encode('utf8')
|
||||||
|
|
||||||
tenant1 = db.open_tenant(b'tenant1')
|
tenant1 = db.open_tenant(b'tenant1')
|
||||||
tenant2 = db.open_tenant(b'tenant2')
|
tenant2 = db.open_tenant(b'tenant2')
|
||||||
|
@ -73,10 +81,12 @@ def test_tenant_operations(db):
|
||||||
tenant1_entry = db[b'\xff\xff/management/tenant_map/tenant1']
|
tenant1_entry = db[b'\xff\xff/management/tenant_map/tenant1']
|
||||||
tenant1_json = json.loads(tenant1_entry)
|
tenant1_json = json.loads(tenant1_entry)
|
||||||
prefix1 = tenant1_json['prefix'].encode('utf8')
|
prefix1 = tenant1_json['prefix'].encode('utf8')
|
||||||
|
assert prefix1 == p1
|
||||||
|
|
||||||
tenant2_entry = db[b'\xff\xff/management/tenant_map/tenant2']
|
tenant2_entry = db[b'\xff\xff/management/tenant_map/tenant2']
|
||||||
tenant2_json = json.loads(tenant2_entry)
|
tenant2_json = json.loads(tenant2_entry)
|
||||||
prefix2 = tenant2_json['prefix'].encode('utf8')
|
prefix2 = tenant2_json['prefix'].encode('utf8')
|
||||||
|
assert prefix2 == p2
|
||||||
|
|
||||||
assert tenant1[b'tenant_test_key'] == b'tenant1'
|
assert tenant1[b'tenant_test_key'] == b'tenant1'
|
||||||
assert db[prefix1 + b'tenant_test_key'] == b'tenant1'
|
assert db[prefix1 + b'tenant_test_key'] == b'tenant1'
|
||||||
|
|
|
@ -604,6 +604,12 @@ class Tester:
|
||||||
self.tenant = self.db.open_tenant(name)
|
self.tenant = self.db.open_tenant(name)
|
||||||
elif inst.op == six.u("TENANT_CLEAR_ACTIVE"):
|
elif inst.op == six.u("TENANT_CLEAR_ACTIVE"):
|
||||||
self.tenant = None
|
self.tenant = None
|
||||||
|
elif inst.op == six.u("TENANT_LIST"):
|
||||||
|
begin = inst.pop()
|
||||||
|
end = inst.pop()
|
||||||
|
limit = inst.pop()
|
||||||
|
tenant_list = fdb.tenant_management.list_tenants(self.db, begin, end, limit)
|
||||||
|
inst.push(tenant_list)
|
||||||
elif inst.op == six.u("UNIT_TESTS"):
|
elif inst.op == six.u("UNIT_TESTS"):
|
||||||
try:
|
try:
|
||||||
test_db_options(db)
|
test_db_options(db)
|
||||||
|
|
Loading…
Reference in New Issue