Files
s3/test/kafka/kafka-client-loadtest/tools/SchemaRegistryTest.java
zooqueen dd74d3e6d6 Replace AGPL MinIO fork with Apache-2.0 SeaweedFS fork; rebrand CLI weed->s3
hanzoai/s3 was an AGPL-3.0 MinIO fork whose network-copyleft blocks embedding
and reselling as a managed service. Replace it wholesale with a fork of
SeaweedFS (github.com/seaweedfs/seaweedfs, Apache-2.0, Go) which ships a
built-in S3 gateway + Filer.

- License: AGPL-3.0 -> Apache-2.0 (upstream LICENSE kept verbatim, incl.
  "Copyright 2025 Chris Lu"); NOTICE added crediting SeaweedFS. No AGPL/BUSL/
  SSPL/GPL or enterprise ("ee") files remain.
- Module: go.mod path set to github.com/hanzoai/s3 with a self-replace
  (replace github.com/seaweedfs/seaweedfs => ./) so the ~1800 internal Go files
  keep their upstream import paths with zero churn. Internal identifiers and
  import paths are intentionally NOT renamed.
- CLI rebrand: the binary is built as `s3` (was `weed`); root usage, per-command
  help/usage/flag strings, shell autocomplete program name, and the product name
  in CLI output now read "Hanzo S3" / `s3`. Users never see `weed`.
  (e.g. `s3 server`, `s3 filer`, `s3 master`, `s3 volume`, `s3 s3`, `s3 mount`.)
- Build: `make` (or `go build -o s3 ./weed`) builds the `s3` binary green;
  `cmd/weed-db` and `cmd/weed-sql` also build; `go vet ./weed/command/` clean.
- README/LLM.md rewritten for Hanzo S3; AGENTS.md/CLAUDE.md symlinks preserved.
- Dropped a 33MB prebuilt Mach-O `stress` binary upstream had committed; `.gitignore`
  updated to ignore the `s3` build output.
2026-06-18 23:41:25 -07:00

125 lines
6.0 KiB
Java

package tools;
import io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient;
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient;
import org.apache.avro.Schema;
import org.apache.avro.SchemaBuilder;
public class SchemaRegistryTest {
private static final String SCHEMA_REGISTRY_URL = "http://localhost:8081";
public static void main(String[] args) {
System.out.println("================================================================================");
System.out.println("Schema Registry Test - Verifying In-Memory Read Optimization");
System.out.println("================================================================================\n");
SchemaRegistryClient schemaRegistry = new CachedSchemaRegistryClient(SCHEMA_REGISTRY_URL, 100);
boolean allTestsPassed = true;
try {
// Test 1: Register first schema
System.out.println("Test 1: Registering first schema (user-value)...");
Schema userValueSchema = SchemaBuilder
.record("User").fields()
.requiredString("name")
.requiredInt("age")
.endRecord();
long startTime = System.currentTimeMillis();
int schema1Id = schemaRegistry.register("user-value", userValueSchema);
long elapsedTime = System.currentTimeMillis() - startTime;
System.out.println("✓ SUCCESS: Schema registered with ID: " + schema1Id + " (took " + elapsedTime + "ms)");
// Test 2: Register second schema immediately (tests read-after-write)
System.out.println("\nTest 2: Registering second schema immediately (user-key)...");
Schema userKeySchema = SchemaBuilder
.record("UserKey").fields()
.requiredString("userId")
.endRecord();
startTime = System.currentTimeMillis();
int schema2Id = schemaRegistry.register("user-key", userKeySchema);
elapsedTime = System.currentTimeMillis() - startTime;
System.out.println("✓ SUCCESS: Schema registered with ID: " + schema2Id + " (took " + elapsedTime + "ms)");
// Test 3: Rapid fire registrations (tests concurrent writes)
System.out.println("\nTest 3: Rapid fire registrations (10 schemas in parallel)...");
startTime = System.currentTimeMillis();
Thread[] threads = new Thread[10];
final boolean[] results = new boolean[10];
for (int i = 0; i < 10; i++) {
final int index = i;
threads[i] = new Thread(() -> {
try {
Schema schema = SchemaBuilder
.record("Test" + index).fields()
.requiredString("field" + index)
.endRecord();
schemaRegistry.register("test-" + index + "-value", schema);
results[index] = true;
} catch (Exception e) {
System.err.println("✗ ERROR in thread " + index + ": " + e.getMessage());
results[index] = false;
}
});
threads[i].start();
}
for (Thread thread : threads) {
thread.join();
}
elapsedTime = System.currentTimeMillis() - startTime;
int successCount = 0;
for (boolean result : results) {
if (result) successCount++;
}
if (successCount == 10) {
System.out.println("✓ SUCCESS: All 10 schemas registered (took " + elapsedTime + "ms total, ~" + (elapsedTime / 10) + "ms per schema)");
} else {
System.out.println("✗ PARTIAL FAILURE: Only " + successCount + "/10 schemas registered");
allTestsPassed = false;
}
// Test 4: Verify we can retrieve all schemas
System.out.println("\nTest 4: Verifying all schemas are retrievable...");
startTime = System.currentTimeMillis();
Schema retrieved1 = schemaRegistry.getById(schema1Id);
Schema retrieved2 = schemaRegistry.getById(schema2Id);
elapsedTime = System.currentTimeMillis() - startTime;
if (retrieved1.equals(userValueSchema) && retrieved2.equals(userKeySchema)) {
System.out.println("✓ SUCCESS: All schemas retrieved correctly (took " + elapsedTime + "ms)");
} else {
System.out.println("✗ FAILURE: Schema mismatch");
allTestsPassed = false;
}
// Summary
System.out.println("\n===============================================================================");
if (allTestsPassed) {
System.out.println("✓ ALL TESTS PASSED!");
System.out.println("===============================================================================");
System.out.println("\nOptimization verified:");
System.out.println("- ForceFlush is NO LONGER NEEDED");
System.out.println("- Subscribers read from in-memory buffer using IsOffsetInMemory()");
System.out.println("- Per-subscriber notification channels provide instant wake-up");
System.out.println("- True concurrent writes without serialization");
System.exit(0);
} else {
System.out.println("✗ SOME TESTS FAILED");
System.out.println("===============================================================================");
System.exit(1);
}
} catch (Exception e) {
System.err.println("\n✗ FATAL ERROR: " + e.getMessage());
e.printStackTrace();
System.exit(1);
}
}
}