Search in sources :

Example 1 with UpdateHandler

use of org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler in project incubator-servicecomb-java-chassis by apache.

the class ApolloConfigurationSourceImplTest method testCreate.

@Test
public void testCreate() throws Exception {
    ApolloConfigurationSourceImpl apolloConfigurationSource = new ApolloConfigurationSourceImpl();
    apolloConfigurationSource.addUpdateListener(result -> Assert.assertTrue(!result.getAdded().isEmpty()));
    UpdateHandler udateHandler = Deencapsulation.getField(apolloConfigurationSource, UpdateHandler.class);
    Map<String, Object> createItems = new HashMap<>();
    createItems.put("testKey", "testValue");
    udateHandler.handle(CREATE, createItems);
}
Also used : UpdateHandler(org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with UpdateHandler

use of org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler in project incubator-servicecomb-java-chassis by apache.

the class ApolloClientTest method testCompareChangedConfig.

@Test
public void testCompareChangedConfig() {
    boolean status = true;
    Map<String, Object> before = new HashMap<>();
    Map<String, Object> after = new HashMap<>();
    ApolloConfigurationSourceImpl impl = new ApolloConfigurationSourceImpl();
    UpdateHandler updateHandler = impl.new UpdateHandler();
    ApolloClient apolloClient = new ApolloClient(updateHandler);
    ConfigRefresh cr = apolloClient.new ConfigRefresh("");
    try {
        Deencapsulation.invoke(cr, "compareChangedConfig", before, after);
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
    status = true;
    before.put("test", "testValue");
    try {
        Deencapsulation.invoke(cr, "compareChangedConfig", before, after);
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
    status = true;
    after.put("test", "testValue2");
    try {
        Deencapsulation.invoke(cr, "compareChangedConfig", before, after);
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
    status = true;
    try {
        Deencapsulation.invoke(cr, "compareChangedConfig", before, after);
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : UpdateHandler(org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler) HashMap(java.util.HashMap) ConfigRefresh(org.apache.servicecomb.config.client.ApolloClient.ConfigRefresh) ApolloConfigurationSourceImpl(org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl) Test(org.junit.Test)

Example 3 with UpdateHandler

use of org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler in project incubator-servicecomb-java-chassis by apache.

the class ApolloClientTest method refreshApolloConfig.

@Test
public void refreshApolloConfig() {
    ApolloConfig apolloConfig = ApolloConfig.INSTANCE;
    RestTemplate rest = Mockito.mock(RestTemplate.class);
    ResponseEntity<String> responseEntity = new ResponseEntity<>("{\"apollo\":\"mocked\", \"configurations\":{\"timeout\":1000}}", HttpStatus.OK);
    Mockito.when(rest.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class), Matchers.<HttpEntity<String>>any(), Matchers.<Class<String>>any())).thenReturn(responseEntity);
    ApolloConfigurationSourceImpl impl = new ApolloConfigurationSourceImpl();
    UpdateHandler updateHandler = impl.new UpdateHandler();
    ApolloClient apolloClient = new ApolloClient(updateHandler);
    Deencapsulation.setField(apolloClient, "rest", rest);
    ConfigRefresh cr = apolloClient.new ConfigRefresh(apolloConfig.getServerUri());
    cr.run();
    Map<String, Object> originMap = Deencapsulation.getField(apolloClient, "originalConfigMap");
    Assert.assertEquals(1, originMap.size());
}
Also used : UpdateHandler(org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler) ResponseEntity(org.springframework.http.ResponseEntity) ConfigRefresh(org.apache.servicecomb.config.client.ApolloClient.ConfigRefresh) RestTemplate(org.springframework.web.client.RestTemplate) ApolloConfigurationSourceImpl(org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl) HttpMethod(org.springframework.http.HttpMethod) Test(org.junit.Test)

Example 4 with UpdateHandler

use of org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler in project java-chassis by ServiceComb.

the class ApolloConfigurationSourceImplTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    ApolloConfigurationSourceImpl apolloConfigurationSource = new ApolloConfigurationSourceImpl();
    apolloConfigurationSource.addUpdateListener(result -> Assert.assertTrue(!result.getChanged().isEmpty()));
    UpdateHandler udateHandler = Deencapsulation.getField(apolloConfigurationSource, UpdateHandler.class);
    Map<String, Object> updateItems = new HashMap<>();
    updateItems.put("testKey", "testValue");
    udateHandler.handle(SET, updateItems);
}
Also used : UpdateHandler(org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 5 with UpdateHandler

use of org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler in project java-chassis by ServiceComb.

the class ApolloConfigurationSourceImplTest method testCreate.

@Test
public void testCreate() throws Exception {
    ApolloConfigurationSourceImpl apolloConfigurationSource = new ApolloConfigurationSourceImpl();
    apolloConfigurationSource.addUpdateListener(result -> Assert.assertTrue(!result.getAdded().isEmpty()));
    UpdateHandler udateHandler = Deencapsulation.getField(apolloConfigurationSource, UpdateHandler.class);
    Map<String, Object> createItems = new HashMap<>();
    createItems.put("testKey", "testValue");
    udateHandler.handle(CREATE, createItems);
}
Also used : UpdateHandler(org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

UpdateHandler (org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler)10 Test (org.junit.Test)10 HashMap (java.util.HashMap)8 ApolloConfigurationSourceImpl (org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl)4 ConfigRefresh (org.apache.servicecomb.config.client.ApolloClient.ConfigRefresh)4 HttpMethod (org.springframework.http.HttpMethod)2 ResponseEntity (org.springframework.http.ResponseEntity)2 RestTemplate (org.springframework.web.client.RestTemplate)2