Search in sources :

Example 91 with Holder

use of org.apache.servicecomb.foundation.common.Holder in project incubator-servicecomb-java-chassis by apache.

the class TestDefaultLogPublisher method init_enabled_default.

@Test
public void init_enabled_default() {
    Holder<Boolean> registered = new Holder<>(false);
    new MockUp<EventBus>(eventBus) {

        @Mock
        void register(Object object) {
            registered.value = true;
        }
    };
    publisher.init(globalRegistry, eventBus, new MetricsBootstrapConfig());
    Assert.assertFalse(registered.value);
}
Also used : MetricsBootstrapConfig(org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig) Holder(org.apache.servicecomb.foundation.common.Holder) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 92 with Holder

use of org.apache.servicecomb.foundation.common.Holder in project incubator-servicecomb-java-chassis by apache.

the class TestDefaultLogPublisher method init_enabled_true.

@Test
public void init_enabled_true() {
    Holder<Boolean> registered = new Holder<>();
    new MockUp<EventBus>(eventBus) {

        @Mock
        void register(Object object) {
            registered.value = true;
        }
    };
    ArchaiusUtils.setProperty(DefaultLogPublisher.ENABLED, true);
    publisher.init(globalRegistry, eventBus, new MetricsBootstrapConfig());
    Assert.assertTrue(registered.value);
}
Also used : MetricsBootstrapConfig(org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig) Holder(org.apache.servicecomb.foundation.common.Holder) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 93 with Holder

use of org.apache.servicecomb.foundation.common.Holder in project incubator-servicecomb-java-chassis by apache.

the class Log4jUtilsTest method init.

@Test
public void init() {
    Holder<Boolean> propertiesLoaded = new Holder<>(false);
    Holder<Boolean> logConfigured = new Holder<>(false);
    Holder<Boolean> mergedFileWritten = new Holder<>(false);
    final Properties logProperties = new Properties();
    logProperties.setProperty("paas.logs.file", "cse.log");
    final ArrayList<Resource> logResList = new ArrayList<>();
    new MockUp<PropertiesLoader>() {

        @Mock
        Properties load() {
            propertiesLoaded.value = true;
            return logProperties;
        }

        @Mock
        List<Resource> getFoundResList() {
            return logResList;
        }
    };
    new MockUp<PropertyConfigurator>() {

        @Mock
        void configure(Properties properties) {
            logConfigured.value = true;
            Assert.assertSame(properties, logProperties);
        }
    };
    new MockUp<Log4jUtils>() {

        @Mock
        void outputFile(List<Resource> resList, Properties properties) {
            mergedFileWritten.value = true;
            Assert.assertSame(logResList, resList);
            Assert.assertSame(logProperties, properties);
        }
    };
    Assert.assertFalse(Deencapsulation.getField(Log4jUtils.class, "inited"));
    try {
        Log4jUtils.init();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    Assert.assertTrue(Deencapsulation.getField(Log4jUtils.class, "inited"));
    Assert.assertTrue(propertiesLoaded.value);
    Assert.assertTrue(logConfigured.value);
    Assert.assertTrue(mergedFileWritten.value);
}
Also used : Holder(org.apache.servicecomb.foundation.common.Holder) Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) MockUp(mockit.MockUp) ArrayList(java.util.ArrayList) List(java.util.List) Properties(java.util.Properties) Test(org.junit.Test)

Example 94 with Holder

use of org.apache.servicecomb.foundation.common.Holder in project incubator-servicecomb-java-chassis by apache.

the class VertxUtils method blockDeploy.

// deploy Verticle and wait for its success. do not call this method in event-loop thread
public static <VERTICLE extends Verticle> boolean blockDeploy(Vertx vertx, Class<VERTICLE> cls, DeploymentOptions options) throws InterruptedException {
    Holder<Boolean> result = new Holder<>();
    CountDownLatch latch = new CountDownLatch(1);
    vertx.deployVerticle(cls.getName(), options, ar -> {
        result.value = ar.succeeded();
        if (ar.failed()) {
            LOGGER.error("deploy vertx failed, cause ", ar.cause());
        }
        latch.countDown();
    });
    latch.await();
    return result.value;
}
Also used : Holder(org.apache.servicecomb.foundation.common.Holder) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 95 with Holder

use of org.apache.servicecomb.foundation.common.Holder in project incubator-servicecomb-java-chassis by apache.

the class CseAsyncClientHttpRequestTest method testNormal.

@Test
public void testNormal() {
    Holder<Invocation> holder = new Holder<>();
    CseAsyncClientHttpRequest client = new CseAsyncClientHttpRequest(URI.create("cse://defaultMicroservice/" + CseAsyncClientHttpRequestTest.CseAsyncClientHttpRequestTestSchema.class.getSimpleName() + "/testbytes"), HttpMethod.POST) {

        @Override
        protected CompletableFuture<ClientHttpResponse> doAsyncInvoke(Invocation invocation) {
            CompletableFuture<ClientHttpResponse> completableFuture = new CompletableFuture<>();
            holder.value = invocation;
            completableFuture.complete(new CseClientHttpResponse(Response.ok("result")));
            return completableFuture;
        }
    };
    byte[] body = "abc".getBytes();
    client.setRequestBody(body);
    client.executeAsync();
    Assert.assertArrayEquals(body, (byte[]) holder.value.getInvocationArguments().get("input"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Invocation(org.apache.servicecomb.core.Invocation) CseClientHttpResponse(org.apache.servicecomb.provider.springmvc.reference.CseClientHttpResponse) Holder(org.apache.servicecomb.foundation.common.Holder) CseClientHttpResponse(org.apache.servicecomb.provider.springmvc.reference.CseClientHttpResponse) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) Test(org.junit.Test)

Aggregations

Holder (org.apache.servicecomb.foundation.common.Holder)108 Test (org.junit.Test)88 MockUp (mockit.MockUp)36 AtomicLong (java.util.concurrent.atomic.AtomicLong)28 Invocation (org.apache.servicecomb.core.Invocation)24 Expectations (mockit.Expectations)22 Vertx (io.vertx.core.Vertx)20 List (java.util.List)18 Response (org.apache.servicecomb.swagger.invocation.Response)18 Mock (mockit.Mock)16 HttpServerFilterBaseForTest (org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest)16 ArrayList (java.util.ArrayList)14 Map (java.util.Map)14 SCBEngine (org.apache.servicecomb.core.SCBEngine)14 ExpectedException (org.junit.rules.ExpectedException)14 CountDownLatch (java.util.concurrent.CountDownLatch)12 Status (javax.ws.rs.core.Response.Status)12 Deencapsulation (mockit.Deencapsulation)12 Mocked (mockit.Mocked)12 ConfigUtil (org.apache.servicecomb.config.ConfigUtil)12