Skip to content

Commit

Permalink
Merge pull request LinkedInAttic#8 from jhartman/master
Browse files Browse the repository at this point in the history
Fixing the zoie trimming test
  • Loading branch information
jhartman committed Jul 29, 2013
2 parents a97cd56 + 6c93864 commit b62c4e4
Showing 1 changed file with 42 additions and 33 deletions.
75 changes: 42 additions & 33 deletions zoie-core/src/test/java/proj/zoie/test/HourglassTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -477,36 +482,39 @@ private void handleSegment(ZoieSegmentReader segmentReader) {
Hourglass<IndexReader, String> hourglass = new Hourglass<IndexReader, String>(factory,
new HourglassTestInterpreter(), new IndexReaderDecorator<IndexReader>() {

@Override
public IndexReader decorate(ZoieIndexReader<IndexReader> indexReader) throws IOException {
return indexReader;
}
@Override
public IndexReader decorate(ZoieIndexReader<IndexReader> indexReader) throws IOException {
return indexReader;
}

@Override
public IndexReader redecorate(IndexReader decorated, ZoieIndexReader<IndexReader> copy, boolean withDeletes)
throws IOException {
// TODO Auto-generated method stub
return decorated;
}
@Override
public IndexReader redecorate(IndexReader decorated, ZoieIndexReader<IndexReader> 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) {
System.out.println(e);
}
MemoryStreamDataProvider<String> memoryProvider = new MemoryStreamDataProvider<String>(
ZoieConfig.DEFAULT_VERSION_COMPARATOR);

memoryProvider.setMaxEventsPerMinute(Long.MAX_VALUE);
memoryProvider.setDataConsumer(hourglass);
memoryProvider.start();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit b62c4e4

Please sign in to comment.