}, zConfig);
HourglassAdmin mbean = new HourglassAdmin(hourglass);
Object readerManager = getFieldValue(hourglass, "_readerMgr");
Object maintenanceThread = getFieldValue(readerManager, "maintenanceThread");
Runnable runnable = (Runnable) getFieldValue(maintenanceThread, "target");
ZoieSystem currentZoie = (ZoieSystem) getFieldValue(hourglass, "_currentZoie");
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
try {
mbeanServer.registerMBean(mbean, new ObjectName("HouseGlass:name=hourglass"));
} catch (Exception e) {
System.out.println(e);
}
MemoryStreamDataProvider<String> memoryProvider = new MemoryStreamDataProvider<String>(
ZoieConfig.DEFAULT_VERSION_COMPARATOR);
memoryProvider.setMaxEventsPerMinute(Long.MAX_VALUE);
memoryProvider.setDataConsumer(hourglass);
memoryProvider.start();
Thread.sleep(200); // wait freshness time for zoie readers.
int initNumDocs = getTotalNumDocs(hourglass);
System.out.println("initial number of DOCs: " + initNumDocs);
boolean wait = false;
for (int i = initNumDocs; i < initNumDocs + 1200; i++) {
List<DataEvent<String>> list = new ArrayList<DataEvent<String>>(2);
list.add(new DataEvent<String>("" + i, "" + i));
memoryProvider.addEvents(list);
System.out.println((i - initNumDocs + 1) + " of " + (1200 - initNumDocs));
if (idxDir.exists()) {
int numDirs = idxDir.listFiles().length;
if (numDirs > maxDirs) {
System.out.println("Set maxDirs to " + numDirs);
maxDirs = numDirs;
}
if (maxDirs >= trimThreshold + 2) {
wait = true;
if (numDirs < minDirs) {
boolean stop = false;
// We want to make sure that number of directories does shrink
// to trimThreshold + 1. Exactly when trimming is done is
// controlled by HourglassReaderManager, which checks trimming
// condition only once per minute.
System.out.println("Set minDirs to " + numDirs);
minDirs = numDirs;
if (minDirs == 2) {
stop = true;
}
if (stop) {
System.out.println("TrimmingTest succeeded, terminate the loop.");
break;
}
}
}
}
synchronized (currentZoie) {
currentZoie.notifyAll();
}
if (wait) {
Thread.sleep(1000);
}
synchronized (runnable) {