address code review comments and add more places for test code

This commit is contained in:
Jon Fu 2022-04-21 16:58:32 -04:00
parent c0aa361885
commit 9e79ff49a6
6 changed files with 30 additions and 4 deletions

View File

@ -38,6 +38,12 @@ The tenant API introduces some new operations:
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
--------------------------------

View File

@ -600,6 +600,10 @@ class ApiTest(Test):
instructions.append(op)
elif op == 'TENANT_CLEAR_ACTIVE':
instructions.append(op)
elif op == 'TENANT_LIST':
instructions.push_args(b'', b'\xff', 10)
instructions.append(op)
self.add_strings(1)
else:
assert False, 'Unknown operation: ' + op

View File

@ -282,7 +282,7 @@ public class TenantManagement {
@Override
public KeyValue 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();
KeyValue result = new KeyValue(tenant, value);

View File

@ -91,7 +91,7 @@ class FDBTenantList(object):
def to_list(self):
return list(self.__iter__())
def __iter__(self, mode=None):
def __iter__(self):
while True:
result = self._iter.__next__()

View File

@ -60,8 +60,16 @@ def test_tenant_operations(db):
fdb.tenant_management.create_tenant(db, b'tenant2')
tenant_list = fdb.tenant_management.list_tenants(db, b'a', b'z', 10).to_list()
assert tenant_list[0] == b'tenant1'
assert tenant_list[1] == b'tenant2'
assert tenant_list[0].key == b'tenant1'
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')
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_json = json.loads(tenant1_entry)
prefix1 = tenant1_json['prefix'].encode('utf8')
assert prefix1 == p1
tenant2_entry = db[b'\xff\xff/management/tenant_map/tenant2']
tenant2_json = json.loads(tenant2_entry)
prefix2 = tenant2_json['prefix'].encode('utf8')
assert prefix2 == p2
assert tenant1[b'tenant_test_key'] == b'tenant1'
assert db[prefix1 + b'tenant_test_key'] == b'tenant1'

View File

@ -604,6 +604,12 @@ class Tester:
self.tenant = self.db.open_tenant(name)
elif inst.op == six.u("TENANT_CLEAR_ACTIVE"):
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"):
try:
test_db_options(db)