apollo-java icon indicating copy to clipboard operation
apollo-java copied to clipboard

addOrModifyProperty修改apollo,异步转同步方法的2个疑问

Open cheese8 opened this issue 10 months ago • 2 comments

如题,testcase中演示了2种方法: 1、以future / Semaphore方式,非侵入(ApolloMockServerApiTest)

Config otherConfig = ConfigService.getConfig(anotherNamespace);

    final SettableFuture<ConfigChangeEvent> future = SettableFuture.create();

    otherConfig.addChangeListener(new ConfigChangeListener() {
      @Override
      public void onChange(ConfigChangeEvent changeEvent) {
        future.set(changeEvent);
      }
    });
 embeddedApollo.deleteProperty(anotherNamespace, "key4");

  ConfigChangeEvent changeEvent = future.get(5, TimeUnit.SECONDS);

疑问1:将这个异步转同步的代码,封装进ApolloTestingServer的addOrModifyProperty是否更合适?

2、埋点(ApolloMockServerSpringIntegrationTest,需拿到TestBean和TestInterestedKeyPrefixesBean对象)

embeddedApollo.addOrModifyProperty(otherNamespace, "someKey", "someValue");
ConfigChangeEvent changeEvent = testBean.futureData.get(5000, TimeUnit.MILLISECONDS);

疑问2:对于这种使用方式,我们需要使用EmbeddedApollo来mock么?直接使用ReflectionTestUtils.setField()更方便?@nobodyiam

cheese8 avatar Apr 21 '24 13:04 cheese8