use of services.moleculer.monitor.ConstantMonitor 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();
}
use of services.moleculer.monitor.ConstantMonitor in project moleculer-java by moleculer-java.
the class CircuitBreakerTest method setUp.
// --- SET UP ---
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void setUp() throws Exception {
sr = new DefaultServiceRegistry();
tr = new TestTransporter();
cb = new DefaultCircuitBreaker();
cb.setMaxErrors(3);
cb.setEnabled(true);
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").breaker(cb).executor(ex).build();
br.start();
for (int i = 0; i < 10; i++) {
Tree config = new Tree();
config.put("nodeID", "node" + i);
Tree actions = config.putMap("actions");
LinkedHashMap<String, Object> action = new LinkedHashMap<>();
action.put("name", "test.test");
((Map) actions.asObject()).put("test.test", action);
sr.addActions(config);
}
}
Aggregations