Skip to content

Conversation

@abhisheksplunk
Copy link
Collaborator

@abhisheksplunk abhisheksplunk commented Dec 19, 2025

Summary: Java Seed-Based Regression Testing Implementation

What We Built

  • Implemented seed storing for Java schema tests
  • Modified writerTest.java.tmpl to generate Java test code that automatically saves and loads failing test seeds
  • Java seeds are stored in a java/ subdirectory
  • Different random number generators (Go vs Java) produce different sequences from the same seed, so they must be kept separate

How It Works
On each test run:

  • Loads previously-failing seeds from stefc/generator/testdata/seeds/java/__seeds.txt
  • Re-tests each stored seed to catch regressions
  • Generates a new random seed using System.nanoTime() for fresh testing

When a test fails:

  • The failing seed is automatically appended to the seed file
  • Subsequent runs will re-test that seed to ensure the bug stays fixed

@github-actions
Copy link

github-actions bot commented Dec 19, 2025

Benchmark Result

Benchmark diff with base branch
goos: linux
goarch: amd64
pkg: github.com/splunk/stef/benchmarks
cpu: AMD EPYC 7763 64-Core Processor                
                                                 │ bench-main.txt │           bench-new.txt            │
                                                 │     sec/op     │    sec/op     vs base              │
SerializeNative/STEF/serialize-4                     8.999m ± 12%   9.040m ±  4%       ~ (p=0.589 n=6)
SerializeNative/STEFU/serialize-4                    34.77m ±  6%   34.42m ±  2%       ~ (p=0.485 n=6)
DeserializeNative/STEF/deser-4                       2.520m ±  1%   2.499m ±  1%       ~ (p=0.132 n=6)
DeserializeNative/STEFU/deser-4                      7.150m ±  0%   7.160m ±  1%       ~ (p=1.000 n=6)
SerializeFromPdata/STEF/serialize-4                  133.5m ±  3%   135.9m ±  3%       ~ (p=0.310 n=6)
SerializeFromPdata/STEFU/serialize-4                 35.01m ±  1%   35.06m ±  1%       ~ (p=0.589 n=6)
DeserializeToPdata/STEF/deserialize-4                45.58m ±  3%   45.60m ±  3%       ~ (p=0.937 n=6)
DeserializeToPdata/STEFU/deserialize-4               62.41m ±  2%   62.79m ±  2%  +0.60% (p=0.041 n=6)
STEFReaderRead-4                                     2.563m ±  1%   2.565m ±  0%       ~ (p=0.818 n=6)
STEFSerializeMultipart/astronomy-otelmetrics-4        3.226 ± 25%    3.431 ± 23%       ~ (p=0.180 n=6)
STEFDeserializeMultipart/astronomy-otelmetrics-4     76.10m ± 12%   82.54m ±  3%  +8.46% (p=0.015 n=6)
ReadSTEF-4                                           2.653m ±  2%   2.582m ±  4%  -2.68% (p=0.026 n=6)
ReadSTEFZ-4                                          3.493m ±  1%   3.287m ±  2%  -5.88% (p=0.002 n=6)
ReadSTEFZWriteSTEF-4                                 8.116m ±  1%   7.553m ±  1%  -6.93% (p=0.002 n=6)
geomean                                              21.14m         21.13m        -0.03%

                                                 │ bench-main.txt │            bench-new.txt            │
                                                 │   sec/point    │   sec/point    vs base              │
SerializeNative/STEF/serialize-4                     134.6n ± 12%    135.1n ±  4%       ~ (p=0.589 n=6)
SerializeNative/STEFU/serialize-4                    520.0n ±  6%    514.9n ±  2%       ~ (p=0.485 n=6)
DeserializeNative/STEF/deser-4                       37.69n ±  1%    37.37n ±  1%       ~ (p=0.102 n=6)
DeserializeNative/STEFU/deser-4                      107.0n ±  0%    107.1n ±  1%       ~ (p=0.998 n=6)
SerializeFromPdata/STEF/serialize-4                  1.998µ ±  3%    2.033µ ±  3%       ~ (p=0.310 n=6)
SerializeFromPdata/STEFU/serialize-4                 523.7n ±  1%    524.4n ±  1%       ~ (p=0.589 n=6)
DeserializeToPdata/STEF/deserialize-4                681.9n ±  3%    682.1n ±  3%       ~ (p=0.937 n=6)
DeserializeToPdata/STEFU/deserialize-4               933.5n ±  2%    939.2n ±  2%  +0.61% (p=0.045 n=6)
STEFReaderRead-4                                     38.34n ±  1%    38.36n ±  0%       ~ (p=0.818 n=6)
STEFSerializeMultipart/astronomy-otelmetrics-4       4.100µ ± 25%    4.361µ ± 23%       ~ (p=0.180 n=6)
STEFDeserializeMultipart/astronomy-otelmetrics-4     96.73n ± 12%   104.90n ±  3%  +8.45% (p=0.015 n=6)
ReadSTEF-4                                           39.71n ±  2%    38.64n ±  4%  -2.69% (p=0.024 n=6)
ReadSTEFZ-4                                          52.27n ±  1%    49.20n ±  2%  -5.88% (p=0.002 n=6)
ReadSTEFZWriteSTEF-4                                 121.5n ±  1%    113.0n ±  1%  -6.95% (p=0.002 n=6)
geomean                                              222.3n          222.2n        -0.03%

                                                 │ bench-main.txt │            bench-new.txt             │
                                                 │      B/op      │     B/op      vs base                │
SerializeNative/STEF/serialize-4                     3.340Mi ± 0%   3.339Mi ± 0%       ~ (p=0.788 n=6)
SerializeNative/STEFU/serialize-4                    7.530Mi ± 0%   7.530Mi ± 0%       ~ (p=0.511 n=6)
DeserializeNative/STEF/deser-4                       934.4Ki ± 0%   934.4Ki ± 0%       ~ (p=1.000 n=6) ¹
DeserializeNative/STEFU/deser-4                      1.471Mi ± 0%   1.471Mi ± 0%       ~ (p=0.455 n=6)
SerializeFromPdata/STEF/serialize-4                  74.82Mi ± 0%   74.82Mi ± 0%       ~ (p=0.513 n=6)
SerializeFromPdata/STEFU/serialize-4                 7.530Mi ± 0%   7.530Mi ± 0%       ~ (p=0.556 n=6)
DeserializeToPdata/STEF/deserialize-4                31.97Mi ± 0%   31.97Mi ± 0%       ~ (p=0.117 n=6)
DeserializeToPdata/STEFU/deserialize-4               38.64Mi ± 0%   38.64Mi ± 0%       ~ (p=0.255 n=6)
STEFReaderRead-4                                     936.2Ki ± 0%   936.2Ki ± 0%       ~ (p=1.000 n=6)
STEFSerializeMultipart/astronomy-otelmetrics-4       3.363Gi ± 0%   3.363Gi ± 0%       ~ (p=0.937 n=6)
STEFDeserializeMultipart/astronomy-otelmetrics-4     20.59Mi ± 0%   20.59Mi ± 0%       ~ (p=0.076 n=6)
ReadSTEF-4                                           936.2Ki ± 0%   936.2Ki ± 0%       ~ (p=0.203 n=6)
ReadSTEFZ-4                                          10.27Mi ± 0%   10.27Mi ± 0%       ~ (p=0.223 n=6)
ReadSTEFZWriteSTEF-4                                 13.43Mi ± 0%   13.43Mi ± 0%       ~ (p=0.567 n=6)
geomean                                              10.48Mi        10.48Mi       -0.00%
¹ all samples are equal

                                                 │ bench-main.txt │            bench-new.txt            │
                                                 │   allocs/op    │  allocs/op   vs base                │
SerializeNative/STEF/serialize-4                      2.647k ± 0%   2.647k ± 1%       ~ (p=0.810 n=6)
SerializeNative/STEFU/serialize-4                      884.0 ± 0%    884.0 ± 0%       ~ (p=1.000 n=6)
DeserializeNative/STEF/deser-4                         465.0 ± 0%    465.0 ± 0%       ~ (p=1.000 n=6) ¹
DeserializeNative/STEFU/deser-4                        469.0 ± 0%    469.0 ± 0%       ~ (p=1.000 n=6) ¹
SerializeFromPdata/STEF/serialize-4                   134.7k ± 0%   134.7k ± 0%       ~ (p=0.567 n=6)
SerializeFromPdata/STEFU/serialize-4                   886.0 ± 0%    886.0 ± 0%       ~ (p=1.000 n=6) ¹
DeserializeToPdata/STEF/deserialize-4                 756.2k ± 0%   756.2k ± 0%       ~ (p=1.000 n=6) ¹
DeserializeToPdata/STEFU/deserialize-4                944.9k ± 0%   944.9k ± 0%       ~ (p=1.000 n=6) ¹
STEFReaderRead-4                                       465.0 ± 0%    465.0 ± 0%       ~ (p=1.000 n=6) ¹
STEFSerializeMultipart/astronomy-otelmetrics-4        13.15M ± 0%   13.15M ± 0%       ~ (p=0.485 n=6)
STEFDeserializeMultipart/astronomy-otelmetrics-4      2.295k ± 0%   2.295k ± 0%       ~ (p=1.000 n=6)
ReadSTEF-4                                             466.0 ± 0%    466.0 ± 0%       ~ (p=1.000 n=6) ¹
ReadSTEFZ-4                                            504.0 ± 0%    504.0 ± 0%       ~ (p=1.000 n=6) ¹
ReadSTEFZWriteSTEF-4                                  1.234k ± 0%   1.234k ± 0%       ~ (p=1.000 n=6)
geomean                                               6.360k        6.360k       +0.00%
¹ all samples are equal
Benchmark result
benchstat bench-new.txt
goos: linux
goarch: amd64
pkg: github.com/splunk/stef/benchmarks
cpu: AMD EPYC 7763 64-Core Processor                
                                                 │ bench-new.txt │
                                                 │    sec/op     │
SerializeNative/STEF/serialize-4                    9.040m ±  4%
SerializeNative/STEFU/serialize-4                   34.42m ±  2%
DeserializeNative/STEF/deser-4                      2.499m ±  1%
DeserializeNative/STEFU/deser-4                     7.160m ±  1%
SerializeFromPdata/STEF/serialize-4                 135.9m ±  3%
SerializeFromPdata/STEFU/serialize-4                35.06m ±  1%
DeserializeToPdata/STEF/deserialize-4               45.60m ±  3%
DeserializeToPdata/STEFU/deserialize-4              62.79m ±  2%
STEFReaderRead-4                                    2.565m ±  0%
STEFSerializeMultipart/astronomy-otelmetrics-4       3.431 ± 23%
STEFDeserializeMultipart/astronomy-otelmetrics-4    82.54m ±  3%
ReadSTEF-4                                          2.582m ±  4%
ReadSTEFZ-4                                         3.287m ±  2%
ReadSTEFZWriteSTEF-4                                7.553m ±  1%
geomean                                             21.13m

                                                 │ bench-new.txt │
                                                 │   sec/point   │
SerializeNative/STEF/serialize-4                    135.1n ±  4%
SerializeNative/STEFU/serialize-4                   514.9n ±  2%
DeserializeNative/STEF/deser-4                      37.37n ±  1%
DeserializeNative/STEFU/deser-4                     107.1n ±  1%
SerializeFromPdata/STEF/serialize-4                 2.033µ ±  3%
SerializeFromPdata/STEFU/serialize-4                524.4n ±  1%
DeserializeToPdata/STEF/deserialize-4               682.1n ±  3%
DeserializeToPdata/STEFU/deserialize-4              939.2n ±  2%
STEFReaderRead-4                                    38.36n ±  0%
STEFSerializeMultipart/astronomy-otelmetrics-4      4.361µ ± 23%
STEFDeserializeMultipart/astronomy-otelmetrics-4    104.9n ±  3%
ReadSTEF-4                                          38.64n ±  4%
ReadSTEFZ-4                                         49.20n ±  2%
ReadSTEFZWriteSTEF-4                                113.0n ±  1%
geomean                                             222.2n

                                                 │ bench-new.txt │
                                                 │     B/op      │
SerializeNative/STEF/serialize-4                    3.339Mi ± 0%
SerializeNative/STEFU/serialize-4                   7.530Mi ± 0%
DeserializeNative/STEF/deser-4                      934.4Ki ± 0%
DeserializeNative/STEFU/deser-4                     1.471Mi ± 0%
SerializeFromPdata/STEF/serialize-4                 74.82Mi ± 0%
SerializeFromPdata/STEFU/serialize-4                7.530Mi ± 0%
DeserializeToPdata/STEF/deserialize-4               31.97Mi ± 0%
DeserializeToPdata/STEFU/deserialize-4              38.64Mi ± 0%
STEFReaderRead-4                                    936.2Ki ± 0%
STEFSerializeMultipart/astronomy-otelmetrics-4      3.363Gi ± 0%
STEFDeserializeMultipart/astronomy-otelmetrics-4    20.59Mi ± 0%
ReadSTEF-4                                          936.2Ki ± 0%
ReadSTEFZ-4                                         10.27Mi ± 0%
ReadSTEFZWriteSTEF-4                                13.43Mi ± 0%
geomean                                             10.48Mi

                                                 │ bench-new.txt │
                                                 │   allocs/op   │
SerializeNative/STEF/serialize-4                     2.647k ± 1%
SerializeNative/STEFU/serialize-4                     884.0 ± 0%
DeserializeNative/STEF/deser-4                        465.0 ± 0%
DeserializeNative/STEFU/deser-4                       469.0 ± 0%
SerializeFromPdata/STEF/serialize-4                  134.7k ± 0%
SerializeFromPdata/STEFU/serialize-4                  886.0 ± 0%
DeserializeToPdata/STEF/deserialize-4                756.2k ± 0%
DeserializeToPdata/STEFU/deserialize-4               944.9k ± 0%
STEFReaderRead-4                                      465.0 ± 0%
STEFSerializeMultipart/astronomy-otelmetrics-4       13.15M ± 0%
STEFDeserializeMultipart/astronomy-otelmetrics-4     2.295k ± 0%
ReadSTEF-4                                            466.0 ± 0%
ReadSTEFZ-4                                           504.0 ± 0%
ReadSTEFZWriteSTEF-4                                 1.234k ± 0%
geomean                                              6.360k

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements seed-based regression testing for Java-generated schema tests. When a randomized test fails, the failing seed is automatically stored in a language-specific seed file and replayed in subsequent test runs to prevent regressions.

Key changes:

  • Refactored Java test template to extract test logic into a separate seed-based method
  • Added automatic seed file management with load/save functionality
  • Created Java-specific seed storage directory with documentation
  • Updated protobuf-generated Go files (unrelated to main feature)

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
stefc/templates/java/writerTest.java.tmpl Refactored test template to support seed loading/saving with file I/O operations
stefc/generator/testdata/seeds/java/com.example.gentest.optional_reset_fail_Struct1_seeds.txt Sample seed file with two previously-failing test seeds
stefc/generator/testdata/seeds/java/com.example.gentest.json_like_Record_seeds.txt Sample seed file with one previously-failing test seed
stefc/generator/testdata/seeds/java/README.md Documentation explaining the seed storage mechanism and naming conventions
go/grpc/stef_proto/destination_grpc.pb.go Regenerated protobuf gRPC bindings with updated protoc tooling versions
go/grpc/stef_proto/destination.pb.go Regenerated protobuf message definitions with updated protoc tooling versions
examples/jsonl/internal/jsonpb/jsonl.pb.go Regenerated protobuf message definitions with updated protoc tooling versions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

} catch (Exception e) {
fail("seed " + seed1 + " optIdx " + optIdx + ": " + e.getMessage());
} catch (Throwable t) {
System.out.printf("Test failed with seed %d optIdx %d: %s%n", seed, optIdx, t);
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

The test method catches all Throwable exceptions but continues execution and only returns false instead of propagating the exception. This means that if an error occurs during test setup (e.g., writer creation fails), the test will silently fail for that optIdx but continue with other iterations. Consider propagating exceptions or at least logging them with the full stack trace. The current implementation only prints the message with toString(), which may not provide enough diagnostic information.

Suggested change
System.out.printf("Test failed with seed %d optIdx %d: %s%n", seed, optIdx, t);
System.out.printf("Test failed with seed %d optIdx %d: %s%n", seed, optIdx, t);
t.printStackTrace(System.out);

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Path seedFilePath = Paths.get("../stefc/generator/testdata/seeds/java/{{ .PackageName }}_{{.StructName}}_seeds.txt");

if (Files.exists(seedFilePath)) {
for (String line : Files.readAllLines(seedFilePath)) {
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

The Files.readAllLines call can throw IOException if the file cannot be read. This exception should be explicitly handled to provide better error messages if the seed file exists but cannot be read due to permission issues or other I/O problems.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@tigrannajaryan tigrannajaryan left a comment

Choose a reason for hiding this comment

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

Great job with the PR, just one minor comment. Once you remove the unrelated file changes, we can merge. I have also run it and verified locally, everything appears to work correctly.

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please do not include unrelated changes in the PR. This file and files in stef_proto don't belong in this PR.

Looks like you are using a different version of protoc and running make all resulted in the changes. You can either restore original files or install the same version of protoc that was used to generate the files last time so that running make all doesn't change the generated files.

In the future we should probably make installing specific protoc version part of https://github.com/splunk/stef/blob/main/CONTRIBUTING.md
It can be done in a future PR.

@tigrannajaryan
Copy link
Collaborator

Please update PR title to reflect the change better.

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