Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Aggarwal <[email protected]>
  • Loading branch information
sarthakaggarwal97 committed Aug 29, 2024
1 parent 7dd70ee commit c258c1f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import static org.opensearch.index.compositeindex.datacube.startree.fileformats.StarTreeWriter.VERSION_CURRENT;
import static org.opensearch.index.mapper.CompositeMappedFieldType.CompositeFieldType.STAR_TREE;

public class StarTreeMetaTests extends OpenSearchTestCase {
public class StarTreeMetadataTests extends OpenSearchTestCase {

private IndexOutput metaOut;
private IndexInput metaIn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,44 @@ public void testGetChildForInvalidDimensionValue() throws IOException {
assertThrows(AssertionError.class, () -> starTreeNode.getChildForDimensionValue(invalidDimensionValue));
}

public void testOnlyRootNodePresent() throws IOException {

Directory directory = newFSDirectory(createTempDir());

IndexOutput dataOut = directory.createOutput("star-tree-data-1", IOContext.DEFAULT);
StarTreeWriter starTreeWriter = new StarTreeWriter();

InMemoryTreeNode node = new InMemoryTreeNode();
node.dimensionId = 0;
node.startDocId = randomInt();
node.endDocId = randomInt();
node.childDimensionId = 1;
node.aggregatedDocId = randomInt();
node.nodeType = randomFrom((byte) 0, (byte) -1, (byte) 2);
node.children = new HashMap<>();

long starTreeDataLength = starTreeWriter.writeStarTree(dataOut, node, 1, "star-tree");

// asserting on the actual length of the star tree data file
assertEquals(starTreeDataLength, 33);
dataOut.close();

IndexInput dataIn = directory.openInput("star-tree-data-1", IOContext.READONCE);
StarTreeMetadata starTreeMetadata = mock(StarTreeMetadata.class);
when(starTreeMetadata.getDataLength()).thenReturn(starTreeDataLength);
when(starTreeMetadata.getDataStartFilePointer()).thenReturn(0L);

FixedLengthStarTreeNode starTreeNode = (FixedLengthStarTreeNode) StarTreeFactory.createStarTree(dataIn, starTreeMetadata);

assertEquals(starTreeNode.getNumChildren(), 0);
assertNull(starTreeNode.getChildForDimensionValue(randomLong()));
assertThrows(IllegalArgumentException.class, () -> starTreeNode.getChildrenIterator().next());
assertThrows(UnsupportedOperationException.class, () -> starTreeNode.getChildrenIterator().remove());

dataIn.close();
directory.close();
}

public void tearDown() throws Exception {
super.tearDown();
dataIn.close();
Expand Down

0 comments on commit c258c1f

Please sign in to comment.