use of org.opensearch.Assertions in project OpenSearch by opensearch-project.
the class TranslogTests method testTranslogCloseInvariant.
// close method should never be called directly from Translog (the only exception is closeOnTragicEvent)
public void testTranslogCloseInvariant() throws IOException {
assumeTrue("test only works with assertions enabled", Assertions.ENABLED);
class MisbehavingTranslog extends Translog {
MisbehavingTranslog(TranslogConfig config, String translogUUID, TranslogDeletionPolicy deletionPolicy, LongSupplier globalCheckpointSupplier, LongSupplier primaryTermSupplier) throws IOException {
super(config, translogUUID, deletionPolicy, globalCheckpointSupplier, primaryTermSupplier, seqNo -> {
});
}
void callCloseDirectly() throws IOException {
close();
}
void callCloseUsingIOUtilsWithExceptionHandling() {
IOUtils.closeWhileHandlingException(this);
}
void callCloseUsingIOUtils() throws IOException {
IOUtils.close(this);
}
void callCloseOnTragicEvent() {
Exception e = new Exception("test tragic exception");
tragedy.setTragicException(e);
closeOnTragicEvent(e);
}
}
globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);
Path path = createTempDir();
final TranslogConfig translogConfig = getTranslogConfig(path);
final TranslogDeletionPolicy deletionPolicy = createTranslogDeletionPolicy(translogConfig.getIndexSettings());
final String translogUUID = Translog.createEmptyTranslog(path, SequenceNumbers.NO_OPS_PERFORMED, shardId, primaryTerm.get());
MisbehavingTranslog misbehavingTranslog = new MisbehavingTranslog(translogConfig, translogUUID, deletionPolicy, () -> globalCheckpoint.get(), primaryTerm::get);
expectThrows(AssertionError.class, () -> misbehavingTranslog.callCloseDirectly());
expectThrows(AssertionError.class, () -> misbehavingTranslog.callCloseUsingIOUtils());
expectThrows(AssertionError.class, () -> misbehavingTranslog.callCloseUsingIOUtilsWithExceptionHandling());
misbehavingTranslog.callCloseOnTragicEvent();
}
Aggregations