Skip to content

CASSANALYTICS-195: Make QuickTheories tests reproducible from a single seed - #240

Open
yifan-c wants to merge 2 commits into
apache:trunkfrom
yifan-c:CASSANALYTICS-195/qt-test-fix
Open

yifan-c wants to merge 2 commits into
apache:trunkfrom
yifan-c:CASSANALYTICS-195/qt-test-fix

Conversation

@yifan-c

@yifan-c yifan-c commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Introduces QTRandom to bridge QT's RandomnessSource into Java Random API

Patch by Yifan Cai; Reviewed by TBD for CASSANALYTICS-195

…e seed

Introduces QTRandom to bridge QT's RandomnessSource into Java Random API

Patch by Yifan Cai; Reviewed by TBD for CASSANALYTICS-195
Comment on lines +34 to +48
public final class QTRandom extends Random
{
private final RandomnessSource source;

public QTRandom(RandomnessSource source)
{
this.source = source;
}

@Override
protected int next(int bits)
{
return (int) source.next(Constraint.between(0, (1L << bits) - 1));
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This class is the core of the patch. The other test code are modified to take QTRandom instead of Random.

private boolean shouldCdcEventWriterFailOnProcessing = false;
private CdcOptions cdcOptions;
private CassandraSource cassandraSource = CassandraSource.DEFAULT;
private Random random = new Random();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Maybe moving this inside the builder to avoid instantiating Random if it is not needed? Just like we do with CdcOptions.

Random first = new QTRandom(new FixedSequenceSource(1L));
Random second = new QTRandom(new FixedSequenceSource(2L));

assertThat(first.nextLong()).isNotEqualTo(second.nextLong());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is "technically" flaky :-P

But let's keep it as is. It would be REAL bad luck to hit it!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants