Files
s3/test/kafka/kafka-client-loadtest/tools/TestSocketReadiness.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

79 lines
3.4 KiB
Java

import java.net.*;
import java.nio.*;
import java.nio.channels.*;
public class TestSocketReadiness {
public static void main(String[] args) throws Exception {
String host = args.length > 0 ? args[0] : "localhost";
int port = args.length > 1 ? Integer.parseInt(args[1]) : 9093;
System.out.println("Testing socket readiness with " + host + ":" + port);
// Test 1: Simple blocking connect
System.out.println("\n=== Test 1: Blocking Socket ===");
try (Socket socket = new Socket()) {
socket.connect(new InetSocketAddress(host, port), 5000);
System.out.println("Blocking socket connected");
System.out.println(" Available bytes: " + socket.getInputStream().available());
Thread.sleep(100);
System.out.println(" Available bytes after 100ms: " + socket.getInputStream().available());
} catch (Exception e) {
System.err.println("Blocking socket failed: " + e.getMessage());
}
// Test 2: Non-blocking NIO socket (like Kafka client uses)
System.out.println("\n=== Test 2: Non-blocking NIO Socket ===");
Selector selector = Selector.open();
SocketChannel channel = SocketChannel.open();
channel.configureBlocking(false);
try {
boolean connected = channel.connect(new InetSocketAddress(host, port));
System.out.println(" connect() returned: " + connected);
SelectionKey key = channel.register(selector, SelectionKey.OP_CONNECT);
int ready = selector.select(5000);
System.out.println(" selector.select() returned: " + ready);
if (ready > 0) {
for (SelectionKey k : selector.selectedKeys()) {
if (k.isConnectable()) {
System.out.println(" isConnectable: true");
boolean finished = channel.finishConnect();
System.out.println(" finishConnect() returned: " + finished);
if (finished) {
k.interestOps(SelectionKey.OP_READ);
// Now check if immediately readable (THIS is what might be wrong)
selector.selectedKeys().clear();
int readReady = selector.selectNow();
System.out.println(" Immediately after connect, selectNow() = " + readReady);
if (readReady > 0) {
System.out.println(" Socket is IMMEDIATELY readable (unexpected!)");
ByteBuffer buf = ByteBuffer.allocate(1);
int bytesRead = channel.read(buf);
System.out.println(" read() returned: " + bytesRead);
} else {
System.out.println(" Socket is NOT immediately readable (correct)");
}
}
}
}
}
System.out.println("NIO socket test completed");
} catch (Exception e) {
System.err.println("NIO socket failed: " + e.getMessage());
e.printStackTrace();
} finally {
channel.close();
selector.close();
}
System.out.println("\nAll tests completed");
}
}