public void verifyEvents(IndexerModelEvent... expectedEvents) { if (events.size() != expectedEvents.length) { if (events.size() > 0) { System.out.println("The events are:"); for (IndexerModelEvent item : events) { System.out.println(item.getType() + " - " + item.getIndexName()); } } else { System.out.println("There are no events."); } assertEquals("Expected number of events", expectedEvents.length, events.size()); } Set<IndexerModelEvent> expectedEventsSet = new HashSet<IndexerModelEvent>(Arrays.asList(expectedEvents)); for (IndexerModelEvent event : expectedEvents) { if (!events.contains(event)) { fail("Expected event not present among events: " + event); } } for (IndexerModelEvent event : events) { if (!expectedEventsSet.contains(event)) { fail("Got an event which is not among the expected events: " + event); } } events.clear(); }
@Override public void run() { while (!stop) { // We need the stop flag because some code (HBase client code) eats // interrupted flags if (Thread.interrupted()) { return; } try { int queueSize = eventQueue.size(); if (queueSize >= 10) { log.warn("EventWorker queue getting large, size = " + queueSize); } IndexerModelEvent event = eventQueue.take(); if (event.getType() == INDEX_ADDED || event.getType() == INDEX_UPDATED) { try { IndexDefinition index = indexerModel.getIndex(event.getIndexName()); if (shouldRunIndexUpdater(index)) { if (indexUpdaters.containsKey(index.getName())) { updateIndexUpdater(index); } else { addIndexUpdater(index); } } else { removeIndexUpdater(index.getName()); } } catch (IndexNotFoundException e) { removeIndexUpdater(event.getIndexName()); } catch (Throwable t) { log.error("Error in IndexerWorker's IndexerModelListener.", t); } } else if (event.getType() == INDEX_REMOVED) { removeIndexUpdater(event.getIndexName()); } } catch (InterruptedException e) { log.info("IndexerWorker.EventWorker interrupted."); return; } catch (Throwable t) { log.error("Error processing indexer model event in IndexerWorker.", t); } } }