Skip to content

Commit

Permalink
Merge pull request #170 from tejash-jl/remove_shard_id_in_async
Browse files Browse the repository at this point in the history
Remove shard id in async
  • Loading branch information
dileepbapat authored Nov 3, 2022
2 parents 75b498e + 26c79a0 commit 6567862
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,19 @@ private void sendNotificationToOwners(JsonNode inputJson, String operation, Stri
}

private String addEntity(JsonNode inputJson, String userId, String entityType, boolean skipSignature) throws Exception {
RecordIdentifier recordId = null;
RecordIdentifier recordId;
try {
logger.info("Add api: entity type: {} and shard propery: {}", entityType, shardManager.getShardProperty());
Shard shard = shardManager.getShard(inputJson.get(entityType).get(shardManager.getShardProperty()));
watch.start("RegistryController.addToExistingEntity");
String resultId;
if (asyncRequest.isEnabled()) {
resultId = registryAsyncService.addEntity(shard, userId, inputJson, skipSignature);
recordId = new RecordIdentifier(null, resultId);
} else {
resultId = registryService.addEntity(shard, userId, inputJson, skipSignature);
recordId = new RecordIdentifier(shard.getShardLabel(), resultId);
}
recordId = new RecordIdentifier(shard.getShardLabel(), resultId);
watch.stop("RegistryController.addToExistingEntity");
logger.info("AddEntity,{}", recordId.toString());
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,4 +821,36 @@ public void shouldReturnFalseIfSignedDataIsNotRevoked() throws Exception {
when(searchService.search(any())).thenReturn(searchResponse);
assertFalse(registryHelper.checkIfCredentialIsRevoked("signedData"));
}

@Test
public void shouldNotContainShardIdInAsyncMode() throws Exception {
JsonNode inviteJson = new ObjectMapper().readTree("{\"Institute\":{\"email\":\"[email protected]\",\"instituteName\":\"gecasu\"}}");
Shard shard = mock(Shard.class);
when(shard.getShardLabel()).thenReturn("1");
when(shardManager.getShard(any())).thenReturn(shard);

when(registryService.addEntity(any(), any(), any(), anyBoolean())).thenReturn(UUID.randomUUID().toString());
when(registryAsyncService.addEntity(any(), any(), any(), anyBoolean())).thenReturn(UUID.randomUUID().toString());
when(asyncRequest.isEnabled()).thenReturn(Boolean.TRUE);
String entity = registryHelper.addEntity(inviteJson, "");
verify(registryService, never()).addEntity(any(), anyString(), any(), anyBoolean());
verify(registryAsyncService, atLeastOnce()).addEntity(any(), anyString(), any(), anyBoolean());
assertFalse(entity.startsWith("1-"));
}

@Test
public void shouldContainShardIdInSyncMode() throws Exception {
JsonNode inviteJson = new ObjectMapper().readTree("{\"Institute\":{\"email\":\"[email protected]\",\"instituteName\":\"gecasu\"}}");
Shard shard = mock(Shard.class);
when(shard.getShardLabel()).thenReturn("1");
when(shardManager.getShard(any())).thenReturn(shard);

when(registryService.addEntity(any(), any(), any(), anyBoolean())).thenReturn(UUID.randomUUID().toString());
when(registryAsyncService.addEntity(any(), any(), any(), anyBoolean())).thenReturn(UUID.randomUUID().toString());
when(asyncRequest.isEnabled()).thenReturn(Boolean.FALSE);
String entity = registryHelper.addEntity(inviteJson, "");
verify(registryService, atLeastOnce()).addEntity(any(), anyString(), any(), anyBoolean());
verify(registryAsyncService, never()).addEntity(any(), anyString(), any(), anyBoolean());
assertTrue(entity.startsWith("1-"));
}
}

0 comments on commit 6567862

Please sign in to comment.