@Test public void do_not_log_errors_when_hazelcast_is_not_active() { logging.setLevel(DEBUG); doThrow(new HazelcastInstanceNotActiveException()).when(sharedHealthState).writeMine(any()); ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class); underTest.start(); verify(executorService).scheduleWithFixedDelay(runnableCaptor.capture(), eq(1L), eq(10L), eq(TimeUnit.SECONDS)); Runnable runnable = runnableCaptor.getValue(); runnable.run(); assertThat(logging.getLogs(ERROR)).isEmpty(); assertThat(logging.hasLog(DEBUG, "Hazelcast is no more active")).isTrue(); } }
public void run() { try { while (true) { int key = (int) (random.nextFloat() * entryCount); int operation = ((int) (random.nextFloat() * 100)); if (operation < getPercentage) { cache.get(String.valueOf(key)); stats.gets.incrementAndGet(); } else if (operation < getPercentage + putPercentage) { cache.put(String.valueOf(key), createValue()); stats.puts.incrementAndGet(); } else { cache.remove(String.valueOf(key)); stats.removes.incrementAndGet(); } } } catch (HazelcastInstanceNotActiveException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } });
public void run() { try { while (true) { int key = (int) (random.nextFloat() * entryCount); int operation = ((int) (random.nextFloat() * 100)); if (operation < getPercentage) { map.get(String.valueOf(key)); stats.gets.incrementAndGet(); } else if (operation < getPercentage + putPercentage) { map.put(String.valueOf(key), createValue()); stats.puts.incrementAndGet(); } else { map.remove(String.valueOf(key)); stats.removes.incrementAndGet(); } } } catch (HazelcastInstanceNotActiveException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } });
@Override public RuntimeException get() { return new HazelcastInstanceNotActiveException(); } })
@Override public boolean removeLifecycleListener(String registrationId) { throw new HazelcastInstanceNotActiveException(); } }
public HazelcastInstanceImpl getOriginal() { final HazelcastInstanceImpl hazelcastInstance = original; if (hazelcastInstance == null) { throw new HazelcastInstanceNotActiveException(); } return hazelcastInstance; }
@Override public Throwable createException(String message, Throwable cause) { return new HazelcastInstanceNotActiveException(message); } });
@Override public RuntimeException get() { return new HazelcastInstanceNotActiveException(); } })
@Override public Throwable createException(String message, Throwable cause) { return new HazelcastInstanceNotActiveException(message); } });
public HazelcastInstanceImpl getOriginal() { final HazelcastInstanceImpl hazelcastInstance = original; if (hazelcastInstance == null) { throw new HazelcastInstanceNotActiveException(); } return hazelcastInstance; }
@Override public String addLifecycleListener(LifecycleListener lifecycleListener) { throw new HazelcastInstanceNotActiveException(); }
protected void throwNotActiveException() { throw new HazelcastInstanceNotActiveException(); }
@Override public boolean removeLifecycleListener(String registrationId) { throw new HazelcastInstanceNotActiveException(); } }
/** * Gets the Service of this AbstractDistributedObject. * * @return the Service of this AbstractDistributedObject * @throws HazelcastInstanceNotActiveException if object is destroyed or HazelcastInstance shutdown. */ public final S getService() { final S s = service; if (s == null) { throw new HazelcastInstanceNotActiveException(); } return s; }
@Override public String addLifecycleListener(LifecycleListener lifecycleListener) { throw new HazelcastInstanceNotActiveException(); }
/** * Gets the Service of this AbstractDistributedObject. * * @return the Service of this AbstractDistributedObject * @throws HazelcastInstanceNotActiveException if object is destroyed or HazelcastInstance shutdown. */ public final S getService() { final S s = service; if (s == null) { throw new HazelcastInstanceNotActiveException(); } return s; }
protected void throwNotActiveException() { throw new HazelcastInstanceNotActiveException(); }
private void failIfNotRunning() { if (!nodeEngine.isRunning()) { throw new HazelcastInstanceNotActiveException(); } }
private boolean engineActive() { NodeState state = context.node.getState(); if (state == NodeState.ACTIVE) { return true; } boolean allowed = state == NodeState.PASSIVE && (op instanceof AllowedDuringPassiveState); if (!allowed) { notifyError(new HazelcastInstanceNotActiveException("State: " + state + " Operation: " + op.getClass())); remote = false; } return allowed; }
public void shutdown() { alive = false; for (Invocation invocation : this) { try { invocation.notifyError(new HazelcastInstanceNotActiveException()); } catch (Throwable e) { logger.warning(invocation + " could not be notified with shutdown message -> " + e.getMessage(), e); } } } }