Search in sources :

Example 1 with TestTransporter

use of services.moleculer.breaker.TestTransporter in project moleculer-java by moleculer-java.

the class EventbusTest method setUp.

// --- SET UP ---
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void setUp() throws Exception {
    sr = new DefaultServiceRegistry();
    tr = new TestTransporter();
    ExecutorService ex = new ExecutorService() {

        @Override
        public void execute(Runnable command) {
            command.run();
        }

        @Override
        public <T> Future<T> submit(Runnable task, T result) {
            task.run();
            return CompletableFuture.completedFuture(result);
        }

        @Override
        public Future<?> submit(Runnable task) {
            task.run();
            return CompletableFuture.completedFuture(null);
        }

        @Override
        public <T> Future<T> submit(Callable<T> task) {
            try {
                return CompletableFuture.completedFuture(task.call());
            } catch (Exception e) {
                CompletableFuture future = CompletableFuture.completedFuture(null);
                future.completeExceptionally(e);
                return future;
            }
        }

        @Override
        public List<Runnable> shutdownNow() {
            return Collections.emptyList();
        }

        @Override
        public void shutdown() {
        }

        @Override
        public boolean isTerminated() {
            return false;
        }

        @Override
        public boolean isShutdown() {
            return false;
        }

        @Override
        public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
            return null;
        }

        @Override
        public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
            return null;
        }

        @Override
        public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException {
            return null;
        }

        @Override
        public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
            return null;
        }

        @Override
        public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
            return false;
        }
    };
    br = ServiceBroker.builder().monitor(new ConstantMonitor()).registry(sr).transporter(tr).nodeID("local").executor(ex).build();
    br.start();
}
Also used : DefaultServiceRegistry(services.moleculer.service.DefaultServiceRegistry) TestTransporter(services.moleculer.breaker.TestTransporter) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutorService(java.util.concurrent.ExecutorService) Collection(java.util.Collection) TimeUnit(java.util.concurrent.TimeUnit) CompletableFuture(java.util.concurrent.CompletableFuture) Future(java.util.concurrent.Future) ConstantMonitor(services.moleculer.monitor.ConstantMonitor) Callable(java.util.concurrent.Callable) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Collection (java.util.Collection)1 Callable (java.util.concurrent.Callable)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 TestTransporter (services.moleculer.breaker.TestTransporter)1 ConstantMonitor (services.moleculer.monitor.ConstantMonitor)1 DefaultServiceRegistry (services.moleculer.service.DefaultServiceRegistry)1