Skip to content

Commit

Permalink
fix AbstractServiceDiscovery.update when doRegister first failed (#14427
Browse files Browse the repository at this point in the history
)
  • Loading branch information
conghuhu authored Jul 16, 2024
1 parent eca57d3 commit c0fec56
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,13 @@ public synchronized void register() throws RuntimeException {
}
boolean revisionUpdated = calOrUpdateInstanceRevision(this.serviceInstance);
if (revisionUpdated) {
reportMetadata(this.metadataInfo);
doRegister(this.serviceInstance);
try {
reportMetadata(this.metadataInfo);
doRegister(this.serviceInstance);
} catch (Exception e) {
this.serviceInstance = null;
throw e;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,35 @@ void test() throws InterruptedException {

applicationModel.destroy();
}

/**
* to fix #14126
*/
@Test
void testUpdateWhenFirstDoRegisterFail() throws InterruptedException {
ApplicationModel applicationModel = FrameworkModel.defaultModel().newApplication();
applicationModel.getApplicationConfigManager().setApplication(new ApplicationConfig("Test"));

URL registryUrl = URL.valueOf("mock://127.0.0.1:12345").addParameter(METADATA_INFO_CACHE_EXPIRE_KEY, 10);
MockServiceDiscovery mockServiceDiscovery =
Mockito.spy(new MockServiceDiscovery(applicationModel, registryUrl));

mockServiceDiscovery.register(URL.valueOf("mock://127.0.0.1:12345")
.setServiceInterface("org.apache.dubbo.registry.service.DemoService"));

Thread.sleep(100);
Mockito.doThrow(new RuntimeException())
.when(mockServiceDiscovery)
.doRegister(Mockito.any(ServiceInstance.class));
Assertions.assertThrows(RuntimeException.class, mockServiceDiscovery::update);

Thread.sleep(100);
Mockito.doNothing().when(mockServiceDiscovery).doRegister(Mockito.any(ServiceInstance.class));
Assertions.assertDoesNotThrow(mockServiceDiscovery::update);

Thread.sleep(100);
Assertions.assertDoesNotThrow(mockServiceDiscovery::update);

applicationModel.destroy();
}
}

0 comments on commit c0fec56

Please sign in to comment.