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
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ protected boolean doRegister() {
microservice.getServiceName(),
microservice.getVersion());

checkSchemaIdSet();
if(!checkSchemaIdSet()) {
return false;
}
} else {
serviceId = srClient.registerMicroservice(microservice);
if (StringUtils.isEmpty(serviceId)) {
Expand Down Expand Up @@ -87,8 +89,12 @@ protected boolean doRegister() {
return registerSchemas();
}

private void checkSchemaIdSet() {
private boolean checkSchemaIdSet() {
Microservice existMicroservice = srClient.getMicroservice(microservice.getServiceId());
if (existMicroservice == null) {
LOGGER.error("Error to get microservice from service center when check schema set");
return false;
}
Set<String> existSchemas = new HashSet<>(existMicroservice.getSchemas());
Set<String> localSchemas = new HashSet<>(microservice.getSchemas());
schemaIdSetMatch = existSchemas.equals(localSchemas);
Expand All @@ -103,7 +109,7 @@ private void checkSchemaIdSet() {
microservice.getVersion(),
localSchemas,
existSchemas);
return;
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we return true or false in case the schema mismatches?

Copy link
Author

@ShakespeareLiu ShakespeareLiu Jul 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this flag just judges whether get the microservice schema dates successfully, another flag "schemaIdSetMatch" judges whether the schema matches.

}

LOGGER.info(
Expand All @@ -113,6 +119,7 @@ private void checkSchemaIdSet() {
microservice.getServiceName(),
microservice.getVersion(),
localSchemas);
return true;
}

private boolean registerSchemas() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,29 @@ public void testAlreadyRegisteredSchemaIdSetNotMatch(@Mocked ServiceRegistryClie
Assert.assertEquals("serviceId", microservice.getIntance().getServiceId());
Assert.assertEquals(1, taskList.size());
}

@Test
public void testAlreadyRegisteredGetSchemaIdSetFailed(@Mocked ServiceRegistryClient srClient) {
Microservice otherMicroservice = new Microservice();
otherMicroservice.setAppId(microservice.getAppId());
otherMicroservice.setServiceName("ms1");
otherMicroservice.addSchema("s1", "");

new Expectations() {
{
srClient.getMicroserviceId(anyString, anyString, anyString);
result = "serviceId";
srClient.getMicroservice(anyString);
result = null;
}
};

MicroserviceRegisterTask registerTask = new MicroserviceRegisterTask(eventBus, srClient, microservice);
registerTask.run();

Assert.assertEquals(false, registerTask.isRegistered());
Assert.assertEquals(false, registerTask.isSchemaIdSetMatch());
Assert.assertEquals("serviceId", microservice.getServiceId());
Assert.assertEquals(1, taskList.size());
}
}