Search in sources :

Example 6 with UpdateHandler

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

the class TestConfigCenterClient method testConnectServer.

@SuppressWarnings("unchecked")
@Test
public void testConnectServer() {
    HttpClientRequest request = Mockito.mock(HttpClientRequest.class);
    Mockito.when(request.method()).thenReturn(HttpMethod.GET);
    Mockito.when(request.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap());
    Buffer rsp = Mockito.mock(Buffer.class);
    Mockito.when(rsp.toJsonObject()).thenReturn(new JsonObject("{\"instances\":[{\"status\":\"UP\",\"endpoints\":[\"rest:0.0.0.0:30103\"],\"hostName\":\"125292-0.0.0.0\",\"serviceName\":\"configServer\",\"https\":false}]}"));
    HttpClientResponse event = Mockito.mock(HttpClientResponse.class);
    Mockito.when(event.bodyHandler(Mockito.any(Handler.class))).then(invocation -> {
        Handler<Buffer> handler = invocation.getArgumentAt(0, Handler.class);
        handler.handle(rsp);
        return null;
    });
    Mockito.when(event.statusCode()).thenReturn(200);
    HttpClient httpClient = Mockito.mock(HttpClient.class);
    Mockito.when(httpClient.get(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.any(Handler.class))).then(invocation -> {
        Handler<HttpClientResponse> handler = invocation.getArgumentAt(3, Handler.class);
        handler.handle(event);
        return request;
    });
    new MockUp<HttpClientWithContext>() {

        @Mock
        public void runOnContext(RunHandler handler) {
            handler.run(httpClient);
        }
    };
    new MockUp<MemberDiscovery>() {

        @Mock
        public void refreshMembers(JsonObject members) {
            Assert.assertTrue(members.size() == 1);
        }
    };
    UpdateHandler updateHandler = new ConfigCenterConfigurationSourceImpl().new UpdateHandler();
    ConfigCenterClient cc = new ConfigCenterClient(updateHandler);
    cc.connectServer();
}
Also used : Buffer(io.vertx.core.buffer.Buffer) UpdateHandler(org.apache.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl.UpdateHandler) ConfigCenterConfigurationSourceImpl(org.apache.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl) JsonObject(io.vertx.core.json.JsonObject) RunHandler(org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext.RunHandler) UpdateHandler(org.apache.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl.UpdateHandler) Handler(io.vertx.core.Handler) MockUp(mockit.MockUp) RunHandler(org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext.RunHandler) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientResponse(io.vertx.core.http.HttpClientResponse) HttpClient(io.vertx.core.http.HttpClient) Test(org.junit.Test)

Aggregations

UpdateHandler (org.apache.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl.UpdateHandler)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 WatchedUpdateListener (com.netflix.config.WatchedUpdateListener)3 WatchedUpdateResult (com.netflix.config.WatchedUpdateResult)3 Handler (io.vertx.core.Handler)3 Buffer (io.vertx.core.buffer.Buffer)3 HttpClient (io.vertx.core.http.HttpClient)3 HttpClientRequest (io.vertx.core.http.HttpClientRequest)3 HttpClientResponse (io.vertx.core.http.HttpClientResponse)3 JsonObject (io.vertx.core.json.JsonObject)3 MockUp (mockit.MockUp)3 ConfigCenterConfigurationSourceImpl (org.apache.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl)3 RunHandler (org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext.RunHandler)3 ConfigRefresh (org.apache.servicecomb.config.client.ConfigCenterClient.ConfigRefresh)2 Subscribe (com.google.common.eventbus.Subscribe)1 MultiMap (io.vertx.core.MultiMap)1 WebSocket (io.vertx.core.http.WebSocket)1