YvCeung commented on code in PR #7576:
URL: https://github.com/apache/incubator-seata/pull/7576#discussion_r2275900976
##########
config/seata-config-consul/src/test/java/org/apache/seata/config/consul/ConsulConfigurationTest.java:
##########
@@ -131,6 +133,31 @@ void testInitSeataConfig() throws Exception {
assertEquals("val1", value, "KV should be visible after a short
await");
}
+ @Test
+ void testOnChangeEvent_skipWhenValueIsBlank() throws InterruptedException {
+
+ String dataId = "seata.properties";
+ ConsulConfiguration.ConsulListener listener = new
ConsulConfiguration.ConsulListener(dataId, null);
+
+ GetValue blankValue = mock(GetValue.class);
+ when(blankValue.getDecodedValue()).thenReturn("");
+
+ Response<GetValue> blankResponse = new Response<>(blankValue, 2L,
false, 2L);
+ when(mockConsulClient.getKVValue(eq(dataId), isNull(),
any(QueryParams.class)))
+ .thenReturn(blankResponse);
+
+ // Run onChangeEvent in a separate thread since it loops indefinitely
+ Thread thread = new Thread(() -> listener.onChangeEvent(new
ConfigurationChangeEvent()));
+ thread.start();
+ Thread.sleep(100);
+ // Interrupt to break the loop
+ thread.interrupt();
+ thread.join(500);
Review Comment:
<img width="1450" height="866" alt="image"
src="https://github.com/user-attachments/assets/ded3e6c1-f02f-411a-8cad-fd2ecc5afedb"
/>
Since this change event of Consul is executed in a continuous loop, if the
current thread is not interrupted, the single test will never end. Our goal is
to verify the business logic, so we give it 100ms to execute and then interrupt
it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]