Skip to content

Commit ff576c2

Browse files
committed
Add two more tests
1 parent e71bbd3 commit ff576c2

File tree

1 file changed

+83
-1
lines changed

1 file changed

+83
-1
lines changed

fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/OnlineIndexingHeartbeatTest.java

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
package com.apple.foundationdb.record.provider.foundationdb;
2222

2323
import com.apple.foundationdb.record.IndexBuildProto;
24+
import com.apple.foundationdb.record.RecordCoreException;
2425
import com.apple.foundationdb.record.metadata.Index;
2526
import com.apple.foundationdb.record.metadata.IndexOptions;
2627
import com.apple.foundationdb.record.metadata.IndexTypes;
2728
import com.apple.foundationdb.record.metadata.expressions.EmptyKeyExpression;
29+
import com.apple.foundationdb.tuple.Tuple;
2830
import org.assertj.core.api.Assertions;
2931
import org.junit.jupiter.api.Test;
3032

@@ -33,14 +35,20 @@
3335
import java.util.List;
3436
import java.util.Map;
3537
import java.util.UUID;
38+
import java.util.concurrent.atomic.AtomicLong;
3639
import java.util.stream.Collectors;
40+
import java.util.stream.IntStream;
3741

3842
import static com.apple.foundationdb.record.metadata.Key.Expressions.field;
43+
import static org.junit.jupiter.api.Assertions.assertThrows;
44+
import static org.junit.jupiter.api.Assertions.assertTrue;
3945

4046
/**
4147
* Verify indexing heartbeat activity (query & clear).
4248
*/
43-
public class OnlineIndexingHeartbeatTest extends OnlineIndexerTest {
49+
class OnlineIndexingHeartbeatTest extends OnlineIndexerTest {
50+
51+
4452
@Test
4553
void testHeartbeatLowLevel() {
4654
List<Index> indexes = new ArrayList<>();
@@ -98,4 +106,78 @@ void testHeartbeatLowLevel() {
98106
Assertions.assertThat(queried).isEmpty();
99107
}
100108
}
109+
110+
@Test
111+
void testMutualIndexersHeartbeatsClearAfterBuild() {
112+
// Assert that the heartbeats are cleared after building
113+
List<Index> indexes = new ArrayList<>();
114+
indexes.add(new Index("indexA", field("num_value_2"), EmptyKeyExpression.EMPTY, IndexTypes.VALUE, IndexOptions.UNIQUE_OPTIONS));
115+
indexes.add(new Index("indexC", field("num_value_unique"), EmptyKeyExpression.EMPTY, IndexTypes.VALUE, IndexOptions.UNIQUE_OPTIONS));
116+
int numRecords = 77;
117+
populateData(numRecords);
118+
int boundarySize = 23;
119+
final List<Tuple> boundariesList = getBoundariesList(numRecords, boundarySize);
120+
FDBRecordStoreTestBase.RecordMetaDataHook hook = allIndexesHook(indexes);
121+
openSimpleMetaData(hook);
122+
disableAll(indexes);
123+
124+
IntStream.rangeClosed(1, 5).parallel().forEach(i -> {
125+
try (OnlineIndexer indexer = newIndexerBuilder(indexes)
126+
.setIndexingPolicy(OnlineIndexer.IndexingPolicy.newBuilder()
127+
.setMutualIndexingBoundaries(boundariesList))
128+
.build()) {
129+
indexer.buildIndex();
130+
}
131+
});
132+
133+
for (Index index : indexes) {
134+
try (OnlineIndexer indexer = newIndexerBuilder(index).build()) {
135+
Assertions.assertThat(indexer.getIndexingHeartbeats(0)).isEmpty();
136+
}
137+
}
138+
}
139+
140+
@Test
141+
void testMutualIndexersHeartbeatsClearAfterCrash() {
142+
// Assert that the heartbeats are cleared after crash
143+
List<Index> indexes = new ArrayList<>();
144+
indexes.add(new Index("indexA", field("num_value_2"), EmptyKeyExpression.EMPTY, IndexTypes.VALUE, IndexOptions.UNIQUE_OPTIONS));
145+
indexes.add(new Index("indexC", field("num_value_unique"), EmptyKeyExpression.EMPTY, IndexTypes.VALUE, IndexOptions.UNIQUE_OPTIONS));
146+
int numRecords = 98;
147+
populateData(numRecords);
148+
int boundarySize = 20;
149+
final List<Tuple> boundariesList = getBoundariesList(numRecords, boundarySize);
150+
FDBRecordStoreTestBase.RecordMetaDataHook hook = allIndexesHook(indexes);
151+
openSimpleMetaData(hook);
152+
disableAll(indexes);
153+
154+
final String testThrowMsg = "Intentionally crash during test";
155+
IntStream.rangeClosed(1, 9).parallel().forEach(i -> {
156+
final AtomicLong counter = new AtomicLong(0);
157+
try (OnlineIndexer indexer = newIndexerBuilder(indexes)
158+
.setIndexingPolicy(OnlineIndexer.IndexingPolicy.newBuilder()
159+
.setMutualIndexingBoundaries(boundariesList)
160+
.build())
161+
.setConfigLoader(old -> {
162+
// Unfortunately, we cannot verify that at least one heartbeat exists from this
163+
// block, as it would have been nesting "asyncToSync" functions. But there are other tests
164+
// that verify the "sync lock" functionality.
165+
if (counter.incrementAndGet() > 2) {
166+
throw new RecordCoreException(testThrowMsg);
167+
}
168+
return old;
169+
})
170+
.build()) {
171+
RecordCoreException e = assertThrows(RecordCoreException.class, indexer::buildIndex);
172+
assertTrue(e.getMessage().contains(testThrowMsg));
173+
}
174+
});
175+
176+
for (Index index : indexes) {
177+
try (OnlineIndexer indexer = newIndexerBuilder(index).build()) {
178+
Assertions.assertThat(indexer.getIndexingHeartbeats(0)).isEmpty();
179+
}
180+
}
181+
}
182+
101183
}

0 commit comments

Comments
 (0)