Search in sources :

Example 96 with Executor

use of java.util.concurrent.Executor in project java-chassis by ServiceComb.

the class ExecutorManager method findExecutor.

// 只会在初始化时执行,一点点重复的查找,没必要做缓存
public static Executor findExecutor(OperationMeta operationMeta) {
    Executor executor = findByKey("cse.executors.Provider." + operationMeta.getSchemaQualifiedName());
    if (executor != null) {
        return executor;
    }
    // 尝试schema级别
    executor = findByKey("cse.executors.Provider." + operationMeta.getSchemaMeta().getName());
    if (executor != null) {
        return executor;
    }
    executor = findByKey("cse.executors.default");
    if (executor != null) {
        return executor;
    }
    return BeanUtils.getBean("cse.executor.default");
}
Also used : Executor(java.util.concurrent.Executor)

Example 97 with Executor

use of java.util.concurrent.Executor in project java-chassis by ServiceComb.

the class MockUtil method mockAbstactRestServer.

public void mockAbstactRestServer() {
    new MockUp<AbstractRestServer<HttpServletResponse>>() {

        @Mock
        protected RestOperationMeta findRestOperation(RestServerRequestInternal restRequest) {
            RestOperationMeta restOperationMeta = Mockito.mock(RestOperationMeta.class);
            OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
            Executor executor = Mockito.mock(Executor.class);
            operationMeta.setExecutor(executor);
            return restOperationMeta;
        }
    };
}
Also used : Executor(java.util.concurrent.Executor) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) RestServerRequestInternal(io.servicecomb.common.rest.codec.RestServerRequestInternal) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockUp(mockit.MockUp) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta)

Example 98 with Executor

use of java.util.concurrent.Executor in project core-java by SpineEventEngine.

the class EventBusBuilderShould method use_passed_executor.

@Test
public void use_passed_executor() {
    final CountDownLatch executorUsageLatch = new CountDownLatch(1);
    final Executor simpleExecutor = new Executor() {

        @Override
        public void execute(Runnable command) {
            // Decrease the counter to ensure this method has been called.
            executorUsageLatch.countDown();
        }
    };
    final EventBus.Builder builder = EventBus.newBuilder().setStorageFactory(storageFactory).setEventStoreStreamExecutor(simpleExecutor);
    final EventBus build = builder.build();
    final Executor streamExecutor = build.getEventStore().getStreamExecutor();
    streamExecutor.execute(mock(Runnable.class));
    try {
        /**
             * The executor configured to operate synchronously,
             * so the latch should already be {@code zero} at this point.
             **/
        executorUsageLatch.await(0, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        fail("The specified executor was not used.");
    }
}
Also used : Executor(java.util.concurrent.Executor) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 99 with Executor

use of java.util.concurrent.Executor in project fast-cast by RuedigerMoeller.

the class TestEchoServer method echoServer.

public static void echoServer(FastCast fc) throws InterruptedException {
    final FCPublisher echoresp = fc.onTransport("default").publish(fc.getPublisherConf("echoresp"));
    final Executor responseExec = Executors.newSingleThreadExecutor();
    final long startUpTime = (int) System.currentTimeMillis();
    startTestTopic(fc, startUpTime);
    startEchoTopic(fc, echoresp, responseExec);
    startUnreliableTopic(fc);
    while (true) {
        Thread.sleep(1000);
    }
}
Also used : Executor(java.util.concurrent.Executor) FCPublisher(org.nustaq.fastcast.api.FCPublisher)

Example 100 with Executor

use of java.util.concurrent.Executor in project core-java by SpineEventEngine.

the class StandShould method use_provided_executor_upon_update_of_watched_type.

@Test
public void use_provided_executor_upon_update_of_watched_type() {
    final Executor executor = mock(Executor.class);
    final BoundedContext boundedContext = BoundedContext.newBuilder().setStand(Stand.newBuilder().setCallbackExecutor(executor)).build();
    final Stand stand = boundedContext.getStand();
    final StandTestProjectionRepository standTestProjectionRepo = new StandTestProjectionRepository(boundedContext);
    stand.registerTypeSupplier(standTestProjectionRepo);
    final Topic projectProjections = requestFactory.topic().allOf(Project.class);
    final MemoizingObserver<Subscription> observer = memoizingObserver();
    stand.subscribe(projectProjections, observer);
    final Subscription subscription = observer.firstResponse();
    final StreamObserver<Response> noopObserver = noOpObserver();
    stand.activate(subscription, emptyUpdateCallback(), noopObserver);
    assertNotNull(subscription);
    verify(executor, never()).execute(any(Runnable.class));
    final ProjectId someId = ProjectId.getDefaultInstance();
    final Version stateVersion = Tests.newVersionWithNumber(1);
    stand.update(asEnvelope(someId, Project.getDefaultInstance(), stateVersion));
    verify(executor, times(1)).execute(any(Runnable.class));
}
Also used : QueryResponse(io.spine.client.QueryResponse) Response(io.spine.base.Response) Executor(java.util.concurrent.Executor) Version(io.spine.base.Version) ProjectId(io.spine.test.projection.ProjectId) BoundedContext(io.spine.server.BoundedContext) StandTestProjectionRepository(io.spine.server.stand.Given.StandTestProjectionRepository) Topic(io.spine.client.Topic) Subscription(io.spine.client.Subscription) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Aggregations

Executor (java.util.concurrent.Executor)267 Test (org.junit.Test)114 CountDownLatch (java.util.concurrent.CountDownLatch)31 ArrayList (java.util.ArrayList)30 IOException (java.io.IOException)28 List (java.util.List)22 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)21 Timeouts (org.neo4j.cluster.timeout.Timeouts)15 Map (java.util.Map)13 ExecutorService (java.util.concurrent.ExecutorService)13 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 InstanceId (org.neo4j.cluster.InstanceId)13 Config (org.neo4j.kernel.configuration.Config)13 File (java.io.File)12 HashMap (java.util.HashMap)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 ObjectInputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory)12 ObjectOutputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory)12 HeartbeatContext (org.neo4j.cluster.protocol.heartbeat.HeartbeatContext)12