Commit 8084a4db authored by Aman Verma's avatar Aman Verma Committed by Kishore Battula
Browse files

Adding exception handling in IsUnique checks

parent 6049f332
...@@ -385,9 +385,13 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore { ...@@ -385,9 +385,13 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
for (String tenant : tenantList) { for (String tenant : tenantList) {
String id = tenant + ":" + schemaId; String id = tenant + ":" + schemaId;
String partitionKey = createSchemaInfoPartitionKey(schemaKindToSchemaIdentity(schemaId)); String partitionKey = createSchemaInfoPartitionKey(schemaKindToSchemaIdentity(schemaId));
Boolean exists = cosmosStore.findItem(tenant, cosmosDBName, schemaInfoContainer, id, partitionKey, SchemaInfoDoc.class).isPresent(); try {
if (exists) { Boolean exists = cosmosStore.findItem(tenant, cosmosDBName, schemaInfoContainer, id, partitionKey, SchemaInfoDoc.class).isPresent();
return false; if (exists) {
return false;
}
} catch (AppException ex) {
log.warning(String.format("Error occurred while performing uniqueness check in tenant '%s'", tenant), ex);
} }
} }
return true; return true;
......
...@@ -256,6 +256,31 @@ public class AzureSchemaInfoStoreTest { ...@@ -256,6 +256,31 @@ public class AzureSchemaInfoStoreTest {
} }
} }
@Test
public void testIsUnique_ApplicationException() throws ApplicationException {
TenantInfo tenant1 = new TenantInfo();
tenant1.setName(commonTenantId);
tenant1.setDataPartitionId(commonTenantId);
TenantInfo tenant2 = new TenantInfo();
tenant2.setName(dataPartitionId);
tenant2.setDataPartitionId(dataPartitionId);
Collection<TenantInfo> tenants = Lists.newArrayList(tenant1, tenant2);
when(this.tenantFactory.listTenantInfo()).thenReturn(tenants);
Optional<SchemaInfoDoc> cosmosItem = Optional.of(schemaInfoDoc);
// An error is encountered while checking uniqueness in one tenant.
doThrow(AppException.class)
.when(cosmosStore)
.findItem(
eq(dataPartitionId),
any(),
any(),
eq(dataPartitionId + ":" + schemaId),
eq(partitionKey),
any());
assertTrue(schemaInfoStore.isUnique(schemaId, commonTenantId));
}
@Test @Test
public void testIsUnique_True() throws ApplicationException { public void testIsUnique_True() throws ApplicationException {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment