From 6c93864ba1c1b55c1d3d112bb0a359cd3c30dfb0 Mon Sep 17 00:00:00 2001 From: Joshua Hartman Date: Tue, 23 Jul 2013 16:26:52 -0700 Subject: [PATCH] Fixing the zoie trimming test --- .../java/proj/zoie/test/HourglassTest.java | 75 +++++++++++-------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/zoie-core/src/test/java/proj/zoie/test/HourglassTest.java b/zoie-core/src/test/java/proj/zoie/test/HourglassTest.java index 026b99ef..8cf636cd 100644 --- a/zoie-core/src/test/java/proj/zoie/test/HourglassTest.java +++ b/zoie-core/src/test/java/proj/zoie/test/HourglassTest.java @@ -417,27 +417,32 @@ public static String now() { return sdf.format(cal.getTime()); } - private void doTrimmingTest(File idxDir, String schedule, int trimThreshold) throws Exception { - HourglassDirectoryManagerFactory factory = new HourglassDirectoryManagerFactory(idxDir, new HourGlassScheduler( - HourGlassScheduler.FREQUENCY.MINUTELY, schedule, true, trimThreshold) { - volatile Long nextTime; - @Override - protected Calendar getNextRoll() { - if (nextTime == null) { - nextTime = System.currentTimeMillis(); - } - nextTime += 1000; - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(nextTime); - return calendar; - } - @Override + private void doTrimmingTest(File idxDir, + String schedule, + int trimThreshold) throws Exception { + + HourglassDirectoryManagerFactory factory = new HourglassDirectoryManagerFactory(idxDir, + new HourGlassScheduler(HourGlassScheduler.FREQUENCY.MINUTELY, schedule, true, trimThreshold) { + volatile Long nextTime; + + @Override + protected Calendar getNextRoll() { + if (nextTime == null) { + nextTime = System.currentTimeMillis(); + } + nextTime += 1000; + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(nextTime); + return calendar; + } + + @Override public Calendar getTrimTime(Calendar now) { Calendar ret = Calendar.getInstance(); - ret.setTimeInMillis(now.getTimeInMillis() + 60L * 60 * 1000 * 48); + ret.setTimeInMillis(now.getTimeInMillis() + 48L * 60L * 60L * 1000L); return ret; } - }); + }); ZoieConfig zConfig = new ZoieConfig(); zConfig.setBatchSize(1); zConfig.setBatchDelay(10); @@ -477,29 +482,31 @@ private void handleSegment(ZoieSegmentReader segmentReader) { Hourglass hourglass = new Hourglass(factory, new HourglassTestInterpreter(), new IndexReaderDecorator() { - @Override - public IndexReader decorate(ZoieIndexReader indexReader) throws IOException { - return indexReader; - } + @Override + public IndexReader decorate(ZoieIndexReader indexReader) throws IOException { + return indexReader; + } - @Override - public IndexReader redecorate(IndexReader decorated, ZoieIndexReader copy, boolean withDeletes) - throws IOException { - // TODO Auto-generated method stub - return decorated; - } + @Override + public IndexReader redecorate(IndexReader decorated, ZoieIndexReader copy, boolean withDeletes) + throws IOException { + // TODO Auto-generated method stub + return decorated; + } + + @Override + public void setDeleteSet(IndexReader reader, DocIdSet docIds) { + // Do nothing + } + }, zConfig); - @Override - public void setDeleteSet(IndexReader reader, DocIdSet docIds) { - // Do nothing - } - }, zConfig); HourglassAdmin mbean = new HourglassAdmin(hourglass); java.lang.reflect.Field field; HourglassReaderManager readerManager = (HourglassReaderManager) getFieldValue(hourglass, "_readerMgr"); HourglassReaderManager.HourglassMaintenance runnable = (HourglassReaderManager.HourglassMaintenance) getFieldValue(readerManager, "hourglassMaintenance"); ZoieSystem currentZoie = (ZoieSystem) getFieldValue(hourglass, "_currentZoie"); MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); + try { mbeanServer.registerMBean(mbean, new ObjectName("HouseGlass:name=hourglass")); } catch (Exception e) { @@ -507,6 +514,7 @@ public void setDeleteSet(IndexReader reader, DocIdSet docIds) { } MemoryStreamDataProvider memoryProvider = new MemoryStreamDataProvider( ZoieConfig.DEFAULT_VERSION_COMPARATOR); + memoryProvider.setMaxEventsPerMinute(Long.MAX_VALUE); memoryProvider.setDataConsumer(hourglass); memoryProvider.start(); @@ -553,7 +561,7 @@ public void setDeleteSet(IndexReader reader, DocIdSet docIds) { Thread.sleep(600); } synchronized (runnable) { - runnable.notifyAll(); + runnable.run(); } synchronized (currentZoie) { //currentZoie.flushEvents(150); @@ -578,6 +586,7 @@ public void setDeleteSet(IndexReader reader, DocIdSet docIds) { memoryProvider.stop(); hourglass.shutdown(); } + private Object getFieldValue(Object obj, String fieldName) { try { java.lang.reflect.Field field = obj.getClass().getDeclaredField(fieldName);