@Test public void testWorkerMonitors() { when(workerManager.getWorkerUuid()).thenReturn("1"); when(workerManager.getExecutionThreadsCount()).thenReturn(5); when(inBuffer.getCapacity()).thenReturn(55); when(outBuffer.getCapacity()).thenReturn(66); Map<WorkerMonitorInfoEnum, Serializable> monitorInfo = workerMonitors.getMonitorInfo(); assertNotNull(monitorInfo.get(WorkerMonitorInfoEnum.TOTAL_MEMORY)); assertNotNull(monitorInfo.get(WorkerMonitorInfoEnum.FREE_MEMORY)); assertNotNull(monitorInfo.get(WorkerMonitorInfoEnum.MAX_MEMORY)); assertNotNull(monitorInfo.get(WorkerMonitorInfoEnum.WORKER_ID)); assertNotNull(monitorInfo.get(WorkerMonitorInfoEnum.EXECUTION_THREADS_AMOUNT)); assertEquals(5, monitorInfo.get(WorkerMonitorInfoEnum.EXECUTION_THREADS_AMOUNT)); assertNotNull(monitorInfo.get(WorkerMonitorInfoEnum.OUTBUFFER_CAPACITY)); assertEquals(66, monitorInfo.get(WorkerMonitorInfoEnum.OUTBUFFER_CAPACITY)); assertNotNull(monitorInfo.get(WorkerMonitorInfoEnum.INBUFFER_CAPACITY)); assertEquals(55, monitorInfo.get(WorkerMonitorInfoEnum.INBUFFER_CAPACITY)); assertNotNull(monitorInfo.get(WorkerMonitorInfoEnum.MONITOR_START_TIME)); assertNotNull(monitorInfo.get(WorkerMonitorInfoEnum.MONITOR_END_TIME)); Long firstStart = (Long) monitorInfo.get(WorkerMonitorInfoEnum.MONITOR_START_TIME); Long firstEnd = (Long) monitorInfo.get(WorkerMonitorInfoEnum.MONITOR_END_TIME); try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } monitorInfo = workerMonitors.getMonitorInfo(); Long secondStart = (Long) monitorInfo.get(WorkerMonitorInfoEnum.MONITOR_START_TIME); Long secondEnd = (Long) monitorInfo.get(WorkerMonitorInfoEnum.MONITOR_END_TIME); assertFalse(firstStart.equals(secondStart)); assertFalse(firstEnd.equals(secondEnd)); }
@Override public synchronized Map<WorkerMonitorInfoEnum, Serializable> getMonitorInfo() { try { Map<WorkerMonitorInfoEnum, Serializable> monitorInfo = Maps.newHashMap(); Runtime runtime = Runtime.getRuntime(); monitorInfo.put(WorkerMonitorInfoEnum.TOTAL_MEMORY, runtime.totalMemory()); monitorInfo.put(WorkerMonitorInfoEnum.FREE_MEMORY, runtime.freeMemory()); monitorInfo.put(WorkerMonitorInfoEnum.MAX_MEMORY, runtime.maxMemory()); monitorInfo.put(WorkerMonitorInfoEnum.WORKER_ID, workerManager.getWorkerUuid()); monitorInfo.put(WorkerMonitorInfoEnum.EXECUTION_THREADS_AMOUNT, workerManager.getExecutionThreadsCount()); monitorInfo.put(WorkerMonitorInfoEnum.OUTBUFFER_CAPACITY, outBuffer.getCapacity()); monitorInfo.put(WorkerMonitorInfoEnum.INBUFFER_CAPACITY, inBuffer.getCapacity()); for (WorkerMonitor monitor : monitors) { monitor.captureMonitorInfo(monitorInfo); } monitorInfo.put(WorkerMonitorInfoEnum.MONITOR_START_TIME, monitorStartTime); monitorInfo.put(WorkerMonitorInfoEnum.MONITOR_END_TIME, System.currentTimeMillis()); return monitorInfo; } finally { resetMonitor(); } }
WorkerMonitorsImpl implements WorkerMonitors { @Override public synchronized Map<WorkerMonitorInfoEnum, Serializable> getMonitorInfo() { try { Map<WorkerMonitorInfoEnum, Serializable> monitorInfo = Maps.newHashMap(); Runtime runtime = Runtime.getRuntime(); monitorInfo.put(WorkerMonitorInfoEnum.TOTAL_MEMORY, runtime.totalMemory()); monitorInfo.put(WorkerMonitorInfoEnum.FREE_MEMORY, runtime.freeMemory()); monitorInfo.put(WorkerMonitorInfoEnum.MAX_MEMORY, runtime.maxMemory()); monitorInfo.put(WorkerMonitorInfoEnum.WORKER_ID, workerManager.getWorkerUuid()); monitorInfo.put(WorkerMonitorInfoEnum.EXECUTION_THREADS_AMOUNT, workerManager.getExecutionThreadsCount()); monitorInfo.put(WorkerMonitorInfoEnum.OUTBUFFER_CAPACITY, outBuffer.getCapacity()); monitorInfo.put(WorkerMonitorInfoEnum.INBUFFER_CAPACITY, inBuffer.getCapacity()); for (WorkerMonitor monitor : monitors) { monitor.captureMonitorInfo(monitorInfo); } monitorInfo.put(WorkerMonitorInfoEnum.MONITOR_START_TIME, monitorStartTime); monitorInfo.put(WorkerMonitorInfoEnum.MONITOR_END_TIME, System.currentTimeMillis()); return monitorInfo; } finally { resetMonitor(); } } }
WorkerMonitorsImpl implements WorkerMonitors { @Override public synchronized Map<WorkerMonitorInfoEnum, Serializable> getMonitorInfo() { try { Map<WorkerMonitorInfoEnum, Serializable> monitorInfo = Maps.newHashMap(); Runtime runtime = Runtime.getRuntime(); monitorInfo.put(WorkerMonitorInfoEnum.TOTAL_MEMORY, runtime.totalMemory()); monitorInfo.put(WorkerMonitorInfoEnum.FREE_MEMORY, runtime.freeMemory()); monitorInfo.put(WorkerMonitorInfoEnum.MAX_MEMORY, runtime.maxMemory()); monitorInfo.put(WorkerMonitorInfoEnum.WORKER_ID, workerManager.getWorkerUuid()); monitorInfo.put(WorkerMonitorInfoEnum.EXECUTION_THREADS_AMOUNT, workerManager.getExecutionThreadsCount()); monitorInfo.put(WorkerMonitorInfoEnum.OUTBUFFER_CAPACITY, outBuffer.getCapacity()); monitorInfo.put(WorkerMonitorInfoEnum.INBUFFER_CAPACITY, inBuffer.getCapacity()); for (WorkerMonitor monitor : monitors) { monitor.captureMonitorInfo(monitorInfo); } monitorInfo.put(WorkerMonitorInfoEnum.MONITOR_START_TIME, monitorStartTime); monitorInfo.put(WorkerMonitorInfoEnum.MONITOR_END_TIME, System.currentTimeMillis()); return monitorInfo; } finally { resetMonitor(); } }  }
WorkerMonitorsImpl implements WorkerMonitors { @Override public synchronized Map<WorkerMonitorInfoEnum, Serializable> getMonitorInfo() { try { Map<WorkerMonitorInfoEnum, Serializable> monitorInfo = Maps.newHashMap(); Runtime runtime = Runtime.getRuntime(); monitorInfo.put(WorkerMonitorInfoEnum.TOTAL_MEMORY, runtime.totalMemory()); monitorInfo.put(WorkerMonitorInfoEnum.FREE_MEMORY, runtime.freeMemory()); monitorInfo.put(WorkerMonitorInfoEnum.MAX_MEMORY, runtime.maxMemory()); monitorInfo.put(WorkerMonitorInfoEnum.WORKER_ID, workerManager.getWorkerUuid()); monitorInfo.put(WorkerMonitorInfoEnum.EXECUTION_THREADS_AMOUNT, workerManager.getExecutionThreadsCount()); monitorInfo.put(WorkerMonitorInfoEnum.OUTBUFFER_CAPACITY, outBuffer.getCapacity()); monitorInfo.put(WorkerMonitorInfoEnum.INBUFFER_CAPACITY, inBuffer.getCapacity()); for (WorkerMonitor monitor : monitors) { monitor.captureMonitorInfo(monitorInfo); } monitorInfo.put(WorkerMonitorInfoEnum.MONITOR_START_TIME, monitorStartTime); monitorInfo.put(WorkerMonitorInfoEnum.MONITOR_END_TIME, System.currentTimeMillis()); return monitorInfo; } finally { resetMonitor(); } }  @PostConstruct void init(); @Override synchronized Map<WorkerMonitorInfoEnum, Serializable> getMonitorInfo(); }
WorkerMonitorsImpl implements WorkerMonitors { @Override public synchronized Map<WorkerMonitorInfoEnum, Serializable> getMonitorInfo() { try { Map<WorkerMonitorInfoEnum, Serializable> monitorInfo = Maps.newHashMap(); Runtime runtime = Runtime.getRuntime(); monitorInfo.put(WorkerMonitorInfoEnum.TOTAL_MEMORY, runtime.totalMemory()); monitorInfo.put(WorkerMonitorInfoEnum.FREE_MEMORY, runtime.freeMemory()); monitorInfo.put(WorkerMonitorInfoEnum.MAX_MEMORY, runtime.maxMemory()); monitorInfo.put(WorkerMonitorInfoEnum.WORKER_ID, workerManager.getWorkerUuid()); monitorInfo.put(WorkerMonitorInfoEnum.EXECUTION_THREADS_AMOUNT, workerManager.getExecutionThreadsCount()); monitorInfo.put(WorkerMonitorInfoEnum.OUTBUFFER_CAPACITY, outBuffer.getCapacity()); monitorInfo.put(WorkerMonitorInfoEnum.INBUFFER_CAPACITY, inBuffer.getCapacity()); for (WorkerMonitor monitor : monitors) { monitor.captureMonitorInfo(monitorInfo); } monitorInfo.put(WorkerMonitorInfoEnum.MONITOR_START_TIME, monitorStartTime); monitorInfo.put(WorkerMonitorInfoEnum.MONITOR_END_TIME, System.currentTimeMillis()); return monitorInfo; } finally { resetMonitor(); } }  @PostConstruct void init(); @Override synchronized Map<WorkerMonitorInfoEnum, Serializable> getMonitorInfo();  }