Skip to content

MINOR: refactor AbstractSegmentsTests to reduce redundancies#21674

Open
mjsax wants to merge 2 commits intoapache:trunkfrom
mjsax:minor-refactor-segment-test
Open

MINOR: refactor AbstractSegmentsTests to reduce redundancies#21674
mjsax wants to merge 2 commits intoapache:trunkfrom
mjsax:minor-refactor-segment-test

Conversation

@mjsax
Copy link
Member

@mjsax mjsax commented Mar 8, 2026

AbstractSegments was refactored in
#21520 moving shared code from
subclassed into AbstractSegments to reduce code duplication. This
implies that we should test shared functionality only once, and not
re-test for each subclass. This PR removes redundant tests from subclass
tests into AbstractSegmentsTest to reduce test duplication.

AbstractSegments was refactored in apache#21520 moving shared code from subclassed into AbstractSegments to reduce code duplication.
This implies that we should test shared functionality only once, and not re-test for each subclass.
This PR removes redundant tests from subclass tests into AbstractSegmentsTest to reduce test duplication.
protected abstract void openSegmentDB(final S segment, final StateStoreContext context);
protected void openSegment(final S segment, final StateStoreContext context) {
segment.openDB(context.appConfigs(), context.stateDir());
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know what you think of this -- I thought it would be good to have a default impl, which works for most Segments but it's a little bit of a hack to make it work. Cf other comments.

public void openDB(final Map<String, Object> configs, final File stateDir) {
super.openDB(configs, stateDir);
// skip the registering step
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we make openDB public on RocksDBStore, we don't need this override any longer.

@Override
protected void openSegmentDB(final KeyValueSegment segment, final StateStoreContext context) {
segment.openDB(context.appConfigs(), context.stateDir());
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed any longer -- can re-sure the new one from AbstractSegments now -- if we don't like the implication of having a default impl in AbstractSegments for this method, would need to add it back here. Similar for other segments classes.

openIterators.clear();
}
if (iterators.size() != 0) {
if (!iterators.isEmpty()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side cleanup

protected void openSegmentDB(final LogicalKeyValueSegment segment, final StateStoreContext context) {
protected void openSegment(final LogicalKeyValueSegment segment, final StateStoreContext context) {
// no-op -- a logical segment is just a view on an underlying physical store
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only LogicalKeyValueSegments cannot re-use the new default from AbstractSegments, so keeping the override here.

assertFalse(first.isOpen());
assertFalse(second.isOpen());
assertFalse(third.isOpen());
public void shouldCreateSegmentsOfCorrectType() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new test

}

@Test
public void shouldOpenExistingSegments() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated test

}

@Test
public void shouldGetSegmentIdsFromTimestamp() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same. Redundant test unified in AbstractSegmentsTest

assertFalse(first.isOpen());
assertFalse(second.isOpen());
assertFalse(third.isOpen());
public void shouldCreateSegmentsOfCorrectType() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new test

}

@Test
public void shouldOpenExistingSegments() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant