Skip to content

Commit

Permalink
tests for making a index loaded into memory concurrent
Browse files Browse the repository at this point in the history
  • Loading branch information
cmacdonald committed Jan 7, 2025
1 parent 62acb64 commit 44580f7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.terrier.structures.concurrent.ConcurrentIndexUtils;
import org.terrier.structures.ConcurrentReadable;
import org.terrier.structures.Index;
import org.terrier.structures.IndexOnDisk;
import org.terrier.structures.IndexFactory;
import org.terrier.tests.ApplicationSetupBasedTest;

Expand All @@ -56,6 +57,30 @@ public class TestConcurrentIndexLoader extends ApplicationSetupBasedTest {
assertTrue(ConcurrentIndexUtils.isConcurrent(concurrent));
assertTrue(concurrent.getLexicon().getClass().isAnnotationPresent(ConcurrentReadable.class));
}

@Test public void testNewIndex_Mem() throws Exception
{
Index index = IndexTestUtils.makeIndex(new String[]{"doc1", "doc2"}, new String[]{"the quick fox", "and all that stuff"});
IndexOnDisk iod = (IndexOnDisk) index;
iod.setIndexProperty("index.inverted.data-source", "fileinmem");
iod.flush();
//IndexRef ref = iod.getIndexRef();
IndexRef ref = IndexRef.of(iod.getIndexRef().toString());
iod.close();

assertFalse(IndexFactory.isLoaded(ref));
index = IndexFactory.of(ref);
System.out.println(((IndexOnDisk) index).getIndexProperty("index.inverted.data-source", null));
assertFalse(ConcurrentIndexUtils.isConcurrent(index));
System.out.println(ref.toString());

IndexRef concRef = ConcurrentIndexLoader.makeConcurrent(ref);
System.out.println(concRef.toString());
Index concurrent = IndexFactory.of(concRef);
assertNotNull(concurrent);
assertTrue(ConcurrentIndexUtils.isConcurrent(concurrent));
assertTrue(concurrent.getLexicon().getClass().isAnnotationPresent(ConcurrentReadable.class));
}

@Test public void testDirectIndex() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.terrier.structures.concurrent;
import org.terrier.structures.*;
import org.terrier.tests.BatchEndToEndTest;
import org.terrier.tests.BatchEndToEndTest.BatchEndToEndTestEventHooks;

import static org.junit.Assert.assertEquals;
public class TestShakParallelTRECQueryingMem extends TestShakParallelTRECQuerying {

static class Hook extends BatchEndToEndTestEventHooks
{
public void finishedIndexing(BatchEndToEndTest test) throws Exception
{
IndexOnDisk iod = IndexOnDisk.createIndex();
iod.setIndexProperty("index.inverted.data-source", "fileinmem");
iod.flush();
iod.close();
}

public void checkIndex(BatchEndToEndTest test, Index index) throws Exception
{
IndexOnDisk iod = (IndexOnDisk) index;
assertEquals("fileinmem", iod.getIndexProperty("index.inverted.data-source", null));
}
}

public TestShakParallelTRECQueryingMem() {
super();
this.testHooks.add(new Hook());
}
}

0 comments on commit 44580f7

Please sign in to comment.