@SmallTest public void testDecrementByOne() { eventCounter.set(DEFAULT_KEY_NAME, DEFAULT_VALUE); eventCounter.decrement(DEFAULT_KEY_NAME); assertTrue( eventCounter.check(DEFAULT_KEY_NAME, DEFAULT_VALUE - EventCounter.DEFAULT_DECREMENT_VALUE)); }
@Test public void testAllExchangeEventsReceived() throws Exception { EventCounter counter = new EventCounter(); _domain.addEventObserver(counter, ExchangeInitiatedEvent.class); _domain.addEventObserver(counter, ExchangeCompletionEvent.class); // send 10 in-only messages and check the counters for (int i = 0; i < 10; i++) { ServiceReference inOnlyService = _domain.createInOnlyService(new QName("ExchangeEvent-0" + i)); Exchange inOnly = inOnlyService.createExchange(); inOnly.send(inOnly.createMessage()); } Assert.assertEquals(10, counter.initiatedCount); Assert.assertEquals(10, counter.completedCount); // initialize counters counter.initiatedCount = 0; counter.completedCount = 0; // send 10 in-out and check the count for (int i = 0; i < 10; i++) { ServiceReference inOutService = _domain.createInOutService( new QName("ExchangeEvent-1" + i), new MockHandler().forwardInToOut()); Exchange inOut = inOutService.createExchange(new MockHandler()); inOut.send(inOut.createMessage()); } Assert.assertEquals(10, counter.initiatedCount); Assert.assertEquals(10, counter.completedCount); }
@Test public void testBindFilteredEventsToMethod() { final MultipleEventSource src = new MultipleEventSource(); final EventCounter counter = new EventCounter(); ClassPublicInterface.bindEventsToMethod( counter, "eventOccurred", src, MultipleEventListener.class, "event1"); assertEquals(0, counter.getCount()); }
private static void calcCacheHitRate( List<Pair<Long, Double>> hitRate, long currentTime, EventCounter cacheHits, EventCounter cacheReq) { long req = cacheReq.calculateCount(); if (req > 0) hitRate.add( new Pair<Long, Double>( currentTime, cacheHits.calculateCount() / (double) cacheReq.calculateCount())); else hitRate.add(new Pair<Long, Double>(currentTime, null)); }
private void doEventCountUpdates() { long newFatal = EventCounter.getFatal(); long newError = EventCounter.getError(); long newWarn = EventCounter.getWarn(); long newInfo = EventCounter.getInfo(); metrics.incrMetric("logFatal", (int) (newFatal - fatalCount)); metrics.incrMetric("logError", (int) (newError - errorCount)); metrics.incrMetric("logWarn", (int) (newWarn - warnCount)); metrics.incrMetric("logInfo", (int) (newInfo - infoCount)); fatalCount = newFatal; errorCount = newError; warnCount = newWarn; infoCount = newInfo; }
@Test public void testExchangeCompletedEvent() { EventCounter counter = new EventCounter(); _domain.addEventObserver(counter, ExchangeCompletionEvent.class); // send in-only and check the count ServiceReference inOnlyService = _domain.createInOnlyService(new QName("ExchangeCompleteEvent-1")); Exchange inOnly = inOnlyService.createExchange(); inOnly.send(inOnly.createMessage()); Assert.assertEquals(1, counter.completedCount); // reset count counter.completedCount = 0; // send in-out and check the count ServiceReference inOutService = _domain.createInOutService( new QName("ExchangeCompleteEvent-2"), new MockHandler().forwardInToOut()); Exchange inOut = inOutService.createExchange(new MockHandler()); inOut.send(inOut.createMessage()); Assert.assertEquals(1, counter.completedCount); }
@SmallTest public void testSingletonSet() { EventCounter.with(context).set(DEFAULT_KEY_NAME, DEFAULT_VALUE); assertTrue(EventCounter.with(context).get(DEFAULT_KEY_NAME) == DEFAULT_VALUE); }
@Override public void tearDown() throws Exception { super.tearDown(); eventCounter.removeAll(); }
@SmallTest public void testResetAll() { eventCounter.set(DEFAULT_KEY_NAME, DEFAULT_VALUE); eventCounter.resetAll(); assertTrue(eventCounter.contains(DEFAULT_KEY_NAME)); }
@SmallTest public void testCheckGreateThanOrEqualTo() { eventCounter.set(DEFAULT_KEY_NAME, DEFAULT_VALUE); assertTrue( eventCounter.check(DEFAULT_KEY_NAME, DEFAULT_VALUE, EventCounter.GREATER_THAN_OR_EQUAL_TO)); }
@SmallTest public void testCheckEqualTo() { eventCounter.set(DEFAULT_KEY_NAME, DEFAULT_VALUE); assertTrue(eventCounter.check(DEFAULT_KEY_NAME, DEFAULT_VALUE, EventCounter.EQUAL_TO)); }
@SmallTest public void testReset() { eventCounter.set(DEFAULT_KEY_NAME, DEFAULT_VALUE); eventCounter.reset(DEFAULT_KEY_NAME); assertTrue(eventCounter.get(DEFAULT_KEY_NAME) == EventCounter.DEFAULT_VALUE); }
public void testCheckLessThanOrEqualTo() { eventCounter.set(DEFAULT_KEY_NAME, DEFAULT_VALUE); assertTrue( eventCounter.check(DEFAULT_KEY_NAME, DEFAULT_VALUE, EventCounter.LESS_THAN_OR_EQUAL_TO)); }
public static double getLookupRate() { return lookupRateTracker.calculateRate(); }
public static void fetchData() { double totalIngestRate = 0.; double totalIngestByteRate = 0.; double totalQueryRate = 0.; double totalQueryByteRate = 0.; double totalScanRate = 0.; long totalEntries = 0; int totalTabletCount = 0; int onlineTabletCount = 0; long totalHoldTime = 0; long totalLookups = 0; boolean retry = true; // only recalc every so often long currentTime = System.currentTimeMillis(); if (currentTime - lastRecalc < REFRESH_TIME * 1000) return; synchronized (Monitor.class) { if (fetching) return; fetching = true; } try { while (retry) { MasterClientService.Iface client = null; try { client = MasterClient.getConnection(HdfsZooInstance.getInstance()); if (client != null) { mmi = client.getMasterStats( Tracer.traceInfo(), SystemCredentials.get().toThrift(HdfsZooInstance.getInstance())); retry = false; } else { mmi = null; } Monitor.gcStatus = fetchGcStatus(); } catch (Exception e) { mmi = null; log.info("Error fetching stats: " + e); } finally { if (client != null) { MasterClient.close(client); } } if (mmi == null) UtilWaitThread.sleep(1000); } if (mmi != null) { int majorCompactions = 0; int minorCompactions = 0; lookupRateTracker.startingUpdates(); indexCacheHitTracker.startingUpdates(); indexCacheRequestTracker.startingUpdates(); dataCacheHitTracker.startingUpdates(); dataCacheRequestTracker.startingUpdates(); for (TabletServerStatus server : mmi.tServerInfo) { TableInfo summary = TableInfoUtil.summarizeTableStats(server); totalIngestRate += summary.ingestRate; totalIngestByteRate += summary.ingestByteRate; totalQueryRate += summary.queryRate; totalScanRate += summary.scanRate; totalQueryByteRate += summary.queryByteRate; totalEntries += summary.recs; totalHoldTime += server.holdTime; totalLookups += server.lookups; majorCompactions += summary.majors.running; minorCompactions += summary.minors.running; lookupRateTracker.updateTabletServer(server.name, server.lastContact, server.lookups); indexCacheHitTracker.updateTabletServer( server.name, server.lastContact, server.indexCacheHits); indexCacheRequestTracker.updateTabletServer( server.name, server.lastContact, server.indexCacheRequest); dataCacheHitTracker.updateTabletServer( server.name, server.lastContact, server.dataCacheHits); dataCacheRequestTracker.updateTabletServer( server.name, server.lastContact, server.dataCacheRequest); } lookupRateTracker.finishedUpdating(); indexCacheHitTracker.finishedUpdating(); indexCacheRequestTracker.finishedUpdating(); dataCacheHitTracker.finishedUpdating(); dataCacheRequestTracker.finishedUpdating(); int totalTables = 0; for (TableInfo tInfo : mmi.tableMap.values()) { totalTabletCount += tInfo.tablets; onlineTabletCount += tInfo.onlineTablets; totalTables++; } Monitor.totalIngestRate = totalIngestRate; Monitor.totalTables = totalTables; totalIngestByteRate = totalIngestByteRate / 1000000.0; Monitor.totalIngestByteRate = totalIngestByteRate; Monitor.totalQueryRate = totalQueryRate; Monitor.totalScanRate = totalScanRate; totalQueryByteRate = totalQueryByteRate / 1000000.0; Monitor.totalQueryByteRate = totalQueryByteRate; Monitor.totalEntries = totalEntries; Monitor.totalTabletCount = totalTabletCount; Monitor.onlineTabletCount = onlineTabletCount; Monitor.totalHoldTime = totalHoldTime; Monitor.totalLookups = totalLookups; ingestRateOverTime.add(new Pair<Long, Double>(currentTime, totalIngestRate)); ingestByteRateOverTime.add(new Pair<Long, Double>(currentTime, totalIngestByteRate)); double totalLoad = 0.; for (TabletServerStatus status : mmi.tServerInfo) { if (status != null) totalLoad += status.osLoad; } loadOverTime.add(new Pair<Long, Double>(currentTime, totalLoad)); minorCompactionsOverTime.add(new Pair<Long, Integer>(currentTime, minorCompactions)); majorCompactionsOverTime.add(new Pair<Long, Integer>(currentTime, majorCompactions)); lookupsOverTime.add(new Pair<Long, Double>(currentTime, lookupRateTracker.calculateRate())); queryRateOverTime.add(new Pair<Long, Integer>(currentTime, (int) totalQueryRate)); queryByteRateOverTime.add(new Pair<Long, Double>(currentTime, totalQueryByteRate)); scanRateOverTime.add(new Pair<Long, Integer>(currentTime, (int) totalScanRate)); calcCacheHitRate( indexCacheHitRateOverTime, currentTime, indexCacheHitTracker, indexCacheRequestTracker); calcCacheHitRate( dataCacheHitRateOverTime, currentTime, dataCacheHitTracker, dataCacheRequestTracker); } try { Monitor.problemSummary = ProblemReports.getInstance().summarize(); Monitor.problemException = null; } catch (Exception e) { log.info("Failed to obtain problem reports ", e); Monitor.problemSummary = Collections.emptyMap(); Monitor.problemException = e; } } finally { synchronized (Monitor.class) { fetching = false; lastRecalc = currentTime; } } }
@SmallTest public void testGetDefault() { eventCounter.remove(DEFAULT_KEY_NAME); assertTrue(eventCounter.get(DEFAULT_KEY_NAME) == EventCounter.DEFAULT_VALUE); }
@SmallTest public void testAdd() { eventCounter.add(DEFAULT_KEY_NAME); assertTrue(eventCounter.get(DEFAULT_KEY_NAME) == EventCounter.DEFAULT_VALUE); }
@SmallTest public void testDecrementByMax() { eventCounter.set(DEFAULT_KEY_NAME, DEFAULT_VALUE); eventCounter.decrement(DEFAULT_KEY_NAME, Integer.MAX_VALUE); assertTrue(eventCounter.check(DEFAULT_KEY_NAME, EventCounter.DEFAULT_VALUE)); }
@SmallTest public void testCheck() { eventCounter.set(DEFAULT_KEY_NAME, DEFAULT_VALUE); assertTrue(eventCounter.check(DEFAULT_KEY_NAME, DEFAULT_VALUE)); }
@SmallTest public void testRemoveAll() { eventCounter.removeAll(); Map<String, ?> map = eventCounter.getAll(); assertTrue(map.size() == 0); }
@SmallTest public void testCheckGreateThan() { eventCounter.set(DEFAULT_KEY_NAME, DEFAULT_VALUE + 1); assertTrue(eventCounter.check(DEFAULT_KEY_NAME, DEFAULT_VALUE, EventCounter.GREATER_THAN)); }
@SmallTest public void testGetAll() { eventCounter.add(DEFAULT_KEY_NAME); Map<String, ?> map = eventCounter.getAll(); assertTrue(map.size() != 0); }
public void testCheckLessThan() { eventCounter.set(DEFAULT_KEY_NAME, DEFAULT_VALUE - 1); assertTrue(eventCounter.check(DEFAULT_KEY_NAME, DEFAULT_VALUE, EventCounter.LESS_THAN)); }
@SmallTest public void testContains() { assertFalse(eventCounter.contains(DEFAULT_KEY_NAME)); }