дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-28 05:22:23 +02:00
fix(database): isolate JDBC console sessions (#6553)
Two SQL consoles on one JDBC data source waited on the same connection, so a long query, cancellation or close in one blocked the other. The JDBC bridge now multiplexes one connection per console inside the existing bridge JVM (capped at 32, with bounded reply buffers), and result reads, cancel and close are routed to the originating console's connection. DuckDB console connections share the database and its attachments with separate temporary tables and session settings; anonymous SQLite and H2 databases keep one shared connection so their contents stay visible. Fixes #6484 Co-authored-by: principalwater <[email protected]>
Цей коміт міститься в:
1 джерело
8fd5ee382d
коміт
4b3717618f
17 files changed
+1637
-354
No files matched your search
@@ -10,7 +10,10 @@ root = Path(__file__).resolve().parent
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--test", action="store_true")
|
||||
parser.add_argument("--out", type=Path, help="output JAR (with --test: the fixture driver for JDBC_FIXTURE_JAR)")
|
||||
parser.add_argument("--duckdb-jar", type=Path, help="run the real DuckDB pipe tests with this existing JDBC jar")
|
||||
args = parser.parse_args()
|
||||
if args.duckdb_jar and not args.test:
|
||||
parser.error("--duckdb-jar requires --test")
|
||||
java_home = os.environ.get("JAVA_HOME")
|
||||
def tool(name):
|
||||
return str(Path(java_home) / "bin" / name) if java_home else name
|
||||
@@ -25,6 +28,10 @@ with tempfile.TemporaryDirectory() as scratch:
|
||||
"-d", classes, *sources], check=True)
|
||||
if args.test:
|
||||
subprocess.run([tool("java"), "-ea", "-cp", classes, "ai.openidea.jdbc.SelfTest"], check=True, timeout=45)
|
||||
if args.duckdb_jar:
|
||||
classpath = os.pathsep.join((str(classes), str(args.duckdb_jar.resolve(strict=True))))
|
||||
subprocess.run([tool("java"), "-ea", "-cp", classpath, "ai.openidea.jdbc.DuckDbSelfTest"],
|
||||
check=True, timeout=45)
|
||||
if not args.test or args.out:
|
||||
with zipfile.ZipFile(args.out or root / "openidea-jdbc-bridge.jar", "w") as jar:
|
||||
for path in sorted(classes.rglob("SelfTest*.class" if args.test else "*.class")):
|
||||
|
||||
Бінарний файл не відображається.
@@ -0,0 +1,225 @@
|
||||
package ai.openidea.jdbc;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* Opt-in framing: request ID, connection ID and field count, then the legacy fields.
|
||||
* Replies carry the request ID before the legacy length and payload. Zero fields
|
||||
* requests cancellation, and a reply with zero length acknowledges it.
|
||||
*/
|
||||
final class MultiplexBridge {
|
||||
private static final int SERVICE = 0;
|
||||
// The service/shared session and closing drivers occupy slots as well.
|
||||
private static final int MAX_CONNECTIONS = 32;
|
||||
private static final int REQUEST_HEADER = Long.BYTES + 2 * Integer.BYTES;
|
||||
private static final long CLOSE_GRACE = TimeUnit.MILLISECONDS.toNanos(1500);
|
||||
|
||||
private final DataInputStream input;
|
||||
private final DataOutputStream output;
|
||||
private final ConcurrentMap<Integer, Session> sessions = new ConcurrentHashMap<>();
|
||||
// Closing drivers still count towards the cap until their Connection.close returns.
|
||||
private final Set<Session> live = ConcurrentHashMap.newKeySet();
|
||||
// Reserve before large writes and encodings, not while JDBC executes. This keeps
|
||||
// frame copies and encoding temporaries within the 192 MiB JVM's headroom.
|
||||
private final Semaphore largeReplies = new Semaphore(1, true);
|
||||
private volatile List<String> settings;
|
||||
private final AtomicBoolean stopping = new AtomicBoolean();
|
||||
|
||||
MultiplexBridge(DataInputStream input, DataOutputStream output) {
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
private static ThreadFactory daemon(String name) {
|
||||
return action -> {
|
||||
var thread = new Thread(action, name);
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
};
|
||||
}
|
||||
|
||||
private static final class Session {
|
||||
final int id;
|
||||
final OpenIdeaJdbc jdbc = new OpenIdeaJdbc();
|
||||
final AtomicReference<OpenIdeaJdbc.Work> active = new AtomicReference<>();
|
||||
final ExecutorService worker = Executors.newSingleThreadExecutor(daemon("jdbc-session"));
|
||||
// A driver may hold Statement.cancel indefinitely. Keep it off the reader and
|
||||
// confine the outstanding calls to this connection.
|
||||
final ExecutorService canceller = new ThreadPoolExecutor(1, 1, 0, TimeUnit.MILLISECONDS,
|
||||
new ArrayBlockingQueue<>(1), daemon("jdbc-cancel"), new ThreadPoolExecutor.DiscardPolicy());
|
||||
|
||||
Session(int id) { this.id = id; }
|
||||
|
||||
void cancel(OpenIdeaJdbc.Work work) {
|
||||
var statement = work.requestCancel();
|
||||
if (statement != null) canceller.execute(() -> OpenIdeaJdbc.Work.cancelStatement(statement));
|
||||
}
|
||||
}
|
||||
|
||||
private void send(long id, ByteArrayOutputStream payload) throws IOException {
|
||||
synchronized (output) {
|
||||
if (stopping.get()) return;
|
||||
output.writeLong(id);
|
||||
OpenIdeaJdbc.send(output, payload);
|
||||
}
|
||||
}
|
||||
|
||||
private static ByteArrayOutputStream status(String error) throws IOException {
|
||||
var bytes = new ByteArrayOutputStream();
|
||||
var result = new DataOutputStream(bytes);
|
||||
result.writeBoolean(error == null);
|
||||
if (error == null) {
|
||||
OpenIdeaJdbc.header(result);
|
||||
OpenIdeaJdbc.end(result, false, -1);
|
||||
} else {
|
||||
OpenIdeaJdbc.text(result, error);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
private void retire(Session session) {
|
||||
if (session == null || !sessions.remove(session.id, session)) return;
|
||||
var work = session.active.get();
|
||||
if (work != null) session.cancel(work);
|
||||
session.worker.execute(() -> {
|
||||
try { session.jdbc.close(); }
|
||||
catch (SQLException | RuntimeException ignored) {}
|
||||
finally { live.remove(session); }
|
||||
});
|
||||
session.worker.shutdown();
|
||||
session.canceller.shutdown();
|
||||
}
|
||||
|
||||
private Connection connect(List<String> options) throws Exception {
|
||||
if (!options.get(0).equals("org.duckdb.DuckDBDriver")) return OpenIdeaJdbc.connect(options);
|
||||
// A second DuckDB login would create a different unnamed in-memory database.
|
||||
// Call duplicate on the service worker so it never races another operation
|
||||
// on the same JDBC Connection.
|
||||
Session service = sessions.get(SERVICE);
|
||||
if (service == null) throw new SQLException("The DuckDB service connection is unavailable");
|
||||
return service.worker.submit(() -> {
|
||||
Connection source = service.jdbc.connection;
|
||||
return (Connection) source.getClass().getMethod("duplicate").invoke(source);
|
||||
}).get();
|
||||
}
|
||||
|
||||
private synchronized void request(long id, int connection, List<String> fields) throws IOException {
|
||||
if (stopping.get()) return;
|
||||
String op = fields.get(0);
|
||||
Session session = sessions.get(connection);
|
||||
if (op.equals("close")) {
|
||||
if (connection == SERVICE || fields.size() != 1) {
|
||||
send(id, status("Invalid JDBC console close request"));
|
||||
} else {
|
||||
retire(session); // Retire the ID before acknowledging, even if the driver is busy.
|
||||
send(id, status(null));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
boolean open = op.equals("open");
|
||||
List<String> options = settings;
|
||||
if (open) {
|
||||
boolean valid = connection == SERVICE
|
||||
? fields.size() >= 6 && fields.size() % 2 == 0
|
||||
: fields.size() == 1 && options != null;
|
||||
if (!valid || session != null) {
|
||||
send(id, status("Invalid JDBC connection open request"));
|
||||
return;
|
||||
}
|
||||
if (live.size() >= MAX_CONNECTIONS) {
|
||||
send(id, status("JDBC connection limit reached. Close a console or wait for its connection to finish closing, then try again."));
|
||||
return;
|
||||
}
|
||||
if (connection == SERVICE) options = List.copyOf(fields.subList(1, fields.size()));
|
||||
session = new Session(connection);
|
||||
sessions.put(connection, session);
|
||||
live.add(session);
|
||||
} else if (session == null) {
|
||||
send(id, status("JDBC connection is closed"));
|
||||
return;
|
||||
}
|
||||
|
||||
var work = new OpenIdeaJdbc.Work(id);
|
||||
if (!session.active.compareAndSet(null, work)) {
|
||||
send(id, status("The JDBC connection is already executing a request"));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
schedule(session, work, fields, open, options);
|
||||
} catch (RejectedExecutionException closed) {
|
||||
session.active.compareAndSet(work, null);
|
||||
send(id, status("JDBC connection is closed"));
|
||||
}
|
||||
}
|
||||
|
||||
private void schedule(Session session, OpenIdeaJdbc.Work work, List<String> fields,
|
||||
boolean open, List<String> options) {
|
||||
session.worker.execute(() -> {
|
||||
try (var buffer = new ReplyBuffer(largeReplies)) {
|
||||
var answer = session.jdbc.reply(work, fields,
|
||||
args -> session.id == SERVICE ? OpenIdeaJdbc.connect(args) : connect(options), buffer);
|
||||
if (open) {
|
||||
if (session.jdbc.connection == null) retire(session);
|
||||
else if (session.id == SERVICE) settings = options;
|
||||
}
|
||||
session.active.compareAndSet(work, null);
|
||||
send(work.id, answer);
|
||||
} catch (Throwable fatal) {
|
||||
abort();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void abort() {
|
||||
if (!stopping.compareAndSet(false, true)) return;
|
||||
// The reader may be blocked on stdin and the worker cannot join itself.
|
||||
var closer = new Thread(() -> {
|
||||
try { closeSessions(); }
|
||||
finally { Runtime.getRuntime().halt(1); }
|
||||
}, "jdbc-broken-pipe");
|
||||
closer.setDaemon(false);
|
||||
closer.start();
|
||||
}
|
||||
|
||||
private void closeSessions() {
|
||||
List<Session> remaining;
|
||||
synchronized (this) { remaining = List.copyOf(live); }
|
||||
for (Session session : remaining) retire(session);
|
||||
long deadline = System.nanoTime() + CLOSE_GRACE;
|
||||
for (Session session : remaining) {
|
||||
long wait = deadline - System.nanoTime();
|
||||
if (wait <= 0) break;
|
||||
try { session.worker.awaitTermination(wait, TimeUnit.NANOSECONDS); }
|
||||
catch (InterruptedException e) { Thread.currentThread().interrupt(); break; }
|
||||
}
|
||||
}
|
||||
|
||||
void run() throws IOException {
|
||||
try {
|
||||
while (!stopping.get()) {
|
||||
long id;
|
||||
try { id = input.readLong(); } catch (EOFException eof) { return; }
|
||||
int connection = input.readInt();
|
||||
int count = input.readInt();
|
||||
if (count == 0) {
|
||||
Session session = sessions.get(connection);
|
||||
var work = session == null ? null : session.active.get();
|
||||
if (work != null && work.id == id) session.cancel(work);
|
||||
send(id, null);
|
||||
} else {
|
||||
request(id, connection, OpenIdeaJdbc.readFields(input, count, REQUEST_HEADER));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (stopping.compareAndSet(false, true)) closeSessions();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public final class OpenIdeaJdbc {
|
||||
static final int LIMIT = 16 * 1024 * 1024;
|
||||
final DataInputStream input = new DataInputStream(new BufferedInputStream(System.in));
|
||||
final DataOutputStream output = new DataOutputStream(new BufferedOutputStream(System.out));
|
||||
Connection connection;
|
||||
boolean catalogs;
|
||||
boolean namespaceKnown;
|
||||
@@ -23,6 +21,7 @@ public final class OpenIdeaJdbc {
|
||||
if (available < 0 || (value != null && value.length() > available))
|
||||
throw new IOException("JDBC result exceeds 16 MiB; select fewer or smaller values");
|
||||
if (value == null) { out.writeInt(-1); return; }
|
||||
ReplyBuffer.beforeEncoding(out, Integer.BYTES + 3 * value.length());
|
||||
byte[] data = value.getBytes(StandardCharsets.UTF_8);
|
||||
if (data.length > available) throw new IOException("JDBC result exceeds 16 MiB; select fewer or smaller values");
|
||||
out.writeInt(data.length);
|
||||
@@ -61,7 +60,7 @@ public final class OpenIdeaJdbc {
|
||||
}
|
||||
}
|
||||
|
||||
void open(List<String> a, DataOutputStream out) throws Exception {
|
||||
static Connection connect(List<String> a) throws Exception {
|
||||
String className = a.get(0), url = a.get(1);
|
||||
Driver driver = Class.forName(className).asSubclass(Driver.class).getConstructor().newInstance();
|
||||
var props = new Properties();
|
||||
@@ -80,6 +79,7 @@ public final class OpenIdeaJdbc {
|
||||
}
|
||||
props.setProperty("duckdb.read_only", "true");
|
||||
}
|
||||
Connection connection;
|
||||
try { connection = driver.connect(url, props); }
|
||||
catch (SQLException e) {
|
||||
if (!duckDbReadOnly) throw e;
|
||||
@@ -89,12 +89,33 @@ public final class OpenIdeaJdbc {
|
||||
if (readOnly && !duckDbReadOnly) {
|
||||
try { connection.setReadOnly(true); }
|
||||
catch (SQLException | UnsupportedOperationException e) {
|
||||
try { connection.close(); } catch (SQLException ignored) {}
|
||||
throw new ReadOnlyUnavailable("The JDBC driver rejected Read-only. Check the driver settings and database account privileges.");
|
||||
}
|
||||
}
|
||||
var m = connection.getMetaData();
|
||||
header(out, "version", "quote");
|
||||
row(out, m.getDatabaseProductName() + " " + m.getDatabaseProductVersion(), m.getIdentifierQuoteString());
|
||||
return connection;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface OpenConnection {
|
||||
Connection open(List<String> args) throws Exception;
|
||||
}
|
||||
|
||||
private void open(List<String> args, DataOutputStream out, OpenConnection opener) throws Exception {
|
||||
Connection opened = opener.open(args);
|
||||
try {
|
||||
var m = opened.getMetaData();
|
||||
header(out, "version", "quote");
|
||||
row(out, m.getDatabaseProductName() + " " + m.getDatabaseProductVersion(), m.getIdentifierQuoteString());
|
||||
connection = opened;
|
||||
} catch (Exception | LinkageError failure) {
|
||||
try { opened.close(); } catch (SQLException ignored) {}
|
||||
throw failure;
|
||||
}
|
||||
}
|
||||
|
||||
void close() throws SQLException {
|
||||
if (connection != null) connection.close();
|
||||
}
|
||||
|
||||
static String pattern(DatabaseMetaData m, String literal) throws SQLException {
|
||||
@@ -210,6 +231,7 @@ public final class OpenIdeaJdbc {
|
||||
if (t == Types.BINARY || t == Types.VARBINARY || t == Types.LONGVARBINARY || t == Types.BLOB) {
|
||||
byte[] b = rs.getBytes(c);
|
||||
if (b != null && b.length > (LIMIT - out.size()) / 2) throw new IOException("JDBC binary value exceeds the result limit");
|
||||
if (b != null) ReplyBuffer.beforeEncoding(out, Integer.BYTES + 2 + 2 * b.length);
|
||||
text(out, b == null ? null : "0x" + HexFormat.of().formatHex(b));
|
||||
} else {
|
||||
text(out, rs.getString(c));
|
||||
@@ -241,15 +263,25 @@ public final class OpenIdeaJdbc {
|
||||
cancelled = true;
|
||||
st = statement;
|
||||
}
|
||||
cancelStatement(st);
|
||||
}
|
||||
|
||||
synchronized Statement requestCancel() {
|
||||
if (cancelled) return null;
|
||||
cancelled = true;
|
||||
return statement;
|
||||
}
|
||||
|
||||
static void cancelStatement(Statement st) {
|
||||
if (st != null) {
|
||||
try { st.cancel(); } catch (SQLException | UnsupportedOperationException ignored) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static List<String> readFields(DataInputStream in, int count) throws IOException {
|
||||
static List<String> readFields(DataInputStream in, int count, int headerBytes) throws IOException {
|
||||
if (count < 1 || count > 8192) throw new IOException("Invalid JDBC field count");
|
||||
int remaining = LIMIT - Long.BYTES - Integer.BYTES;
|
||||
int remaining = LIMIT - headerBytes;
|
||||
var fields = new ArrayList<String>(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
remaining -= Integer.BYTES;
|
||||
@@ -263,14 +295,18 @@ public final class OpenIdeaJdbc {
|
||||
return fields;
|
||||
}
|
||||
|
||||
ByteArrayOutputStream reply(Work work, List<String> a) throws IOException {
|
||||
var buffer = new ByteArrayOutputStream();
|
||||
var reply = new DataOutputStream(buffer);
|
||||
ByteArrayOutputStream reply(Work work, List<String> a, OpenConnection opener) throws IOException {
|
||||
return reply(work, a, opener, new ByteArrayOutputStream());
|
||||
}
|
||||
|
||||
ByteArrayOutputStream reply(Work work, List<String> a, OpenConnection opener,
|
||||
ByteArrayOutputStream buffer) throws IOException {
|
||||
var reply = ReplyBuffer.writer(buffer);
|
||||
String op = a.remove(0);
|
||||
try {
|
||||
reply.writeBoolean(true);
|
||||
switch (op) {
|
||||
case "open" -> open(a, reply);
|
||||
case "open" -> open(a, reply, opener);
|
||||
case "schemas" -> schemas(reply);
|
||||
case "tables", "columns", "schemaColumns" -> metadata(op, a, reply);
|
||||
case "namespace" -> {
|
||||
@@ -327,8 +363,9 @@ public final class OpenIdeaJdbc {
|
||||
}
|
||||
if (!op.equals("query") && !op.equals("page")) end(reply, false, -1);
|
||||
} catch (Exception | LinkageError e) {
|
||||
buffer = new ByteArrayOutputStream();
|
||||
reply = new DataOutputStream(buffer);
|
||||
if (buffer instanceof ReplyBuffer bounded) bounded.reset();
|
||||
else buffer = new ByteArrayOutputStream();
|
||||
reply = ReplyBuffer.writer(buffer);
|
||||
reply.writeBoolean(false);
|
||||
if ((e instanceof ClassNotFoundException || e instanceof NoClassDefFoundError)
|
||||
&& e.getMessage() != null && e.getMessage().matches("[A-Za-z0-9_.$/]+")) {
|
||||
@@ -349,14 +386,15 @@ public final class OpenIdeaJdbc {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
synchronized void send(ByteArrayOutputStream reply) throws IOException {
|
||||
output.writeInt(reply == null ? 0 : reply.size());
|
||||
if (reply != null) reply.writeTo(output);
|
||||
output.flush();
|
||||
static void send(DataOutputStream output, ByteArrayOutputStream reply) throws IOException {
|
||||
synchronized (output) {
|
||||
output.writeInt(reply == null ? 0 : reply.size());
|
||||
if (reply != null) reply.writeTo(output);
|
||||
output.flush();
|
||||
}
|
||||
}
|
||||
|
||||
void run() throws IOException {
|
||||
System.setOut(System.err);
|
||||
void run(DataInputStream input, DataOutputStream output) throws IOException {
|
||||
var active = new AtomicReference<Work>();
|
||||
var worker = Executors.newSingleThreadExecutor(r -> {
|
||||
var thread = new Thread(r, "jdbc-session");
|
||||
@@ -371,17 +409,17 @@ public final class OpenIdeaJdbc {
|
||||
if (count == 0) {
|
||||
var work = active.get();
|
||||
if (work != null && work.id == id) work.cancel();
|
||||
send(null); // Acknowledge even a cancel that raced with a completed request.
|
||||
send(output, null); // Acknowledge even a cancel that raced with a completed request.
|
||||
continue;
|
||||
}
|
||||
var fields = readFields(input, count);
|
||||
var fields = readFields(input, count, Long.BYTES + Integer.BYTES);
|
||||
var work = new Work(id);
|
||||
if (!active.compareAndSet(null, work)) throw new IOException("Overlapping JDBC requests");
|
||||
worker.execute(() -> {
|
||||
try {
|
||||
var result = reply(work, fields);
|
||||
var result = reply(work, fields, OpenIdeaJdbc::connect);
|
||||
active.compareAndSet(work, null);
|
||||
send(result);
|
||||
send(output, result);
|
||||
} catch (Throwable fatal) {
|
||||
// Without a complete frame the parent must discard this session.
|
||||
Runtime.getRuntime().halt(1);
|
||||
@@ -394,8 +432,19 @@ public final class OpenIdeaJdbc {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
var input = new DataInputStream(new BufferedInputStream(System.in));
|
||||
boolean multiplex = args.length == 1 && args[0].equals("--multiplex");
|
||||
// PrintStream swallows broken pipe errors. The multiplexed writer needs
|
||||
// the failure so it can close all peers and terminate the transport.
|
||||
OutputStream wire = multiplex ? new FileOutputStream(FileDescriptor.out) : System.out;
|
||||
var output = new DataOutputStream(new BufferedOutputStream(wire));
|
||||
System.setOut(System.err);
|
||||
if (multiplex) {
|
||||
new MultiplexBridge(input, output).run();
|
||||
return;
|
||||
}
|
||||
var bridge = new OpenIdeaJdbc();
|
||||
try { bridge.run(); }
|
||||
finally { if (bridge.connection != null) bridge.connection.close(); }
|
||||
try { bridge.run(input, output); }
|
||||
finally { bridge.close(); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package ai.openidea.jdbc;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
/** Small replies have their own bounded buffer. Only one large reply is encoded at a time. */
|
||||
final class ReplyBuffer extends ByteArrayOutputStream {
|
||||
private static final int SMALL = 64 * 1024;
|
||||
private static final String BUDGET_ERROR =
|
||||
"JDBC result exceeds the concurrent reply budget. Select fewer or smaller values.";
|
||||
private final Semaphore budget;
|
||||
private boolean reserved;
|
||||
|
||||
ReplyBuffer(Semaphore budget) { this.budget = budget; }
|
||||
|
||||
private static final class Writer extends DataOutputStream {
|
||||
final ReplyBuffer buffer;
|
||||
Writer(ReplyBuffer buffer) {
|
||||
super(buffer);
|
||||
this.buffer = buffer;
|
||||
}
|
||||
}
|
||||
|
||||
static DataOutputStream writer(ByteArrayOutputStream buffer) {
|
||||
return buffer instanceof ReplyBuffer bounded ? new Writer(bounded) : new DataOutputStream(buffer);
|
||||
}
|
||||
|
||||
static void beforeEncoding(DataOutputStream output, int bound) {
|
||||
if (output instanceof Writer writer) {
|
||||
// A field this size may already own a large value from the driver. Do not
|
||||
// retain it while waiting behind another large frame.
|
||||
writer.buffer.reserve((long) writer.buffer.count + bound, bound <= SMALL);
|
||||
}
|
||||
}
|
||||
|
||||
private void reserve(long size, boolean wait) {
|
||||
if (reserved || size <= SMALL) return;
|
||||
try {
|
||||
if (wait) budget.acquire();
|
||||
else if (!budget.tryAcquire()) throw new UncheckedIOException(new IOException(BUDGET_ERROR));
|
||||
reserved = true;
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new UncheckedIOException(new IOException("JDBC reply interrupted", e));
|
||||
}
|
||||
}
|
||||
|
||||
private void grow(int extra) {
|
||||
if (extra > OpenIdeaJdbc.LIMIT - count)
|
||||
throw new UncheckedIOException(new IOException("JDBC result exceeds 16 MiB"));
|
||||
int needed = count + extra;
|
||||
reserve(needed, true);
|
||||
if (needed > buf.length) {
|
||||
int limit = reserved ? OpenIdeaJdbc.LIMIT : SMALL;
|
||||
buf = Arrays.copyOf(buf, Math.min(limit, Math.max(needed, buf.length * 2)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override public synchronized void write(int value) {
|
||||
grow(1);
|
||||
buf[count++] = (byte) value;
|
||||
}
|
||||
|
||||
@Override public synchronized void write(byte[] data, int offset, int size) {
|
||||
Objects.checkFromIndexSize(offset, size, data.length);
|
||||
grow(size);
|
||||
System.arraycopy(data, offset, buf, count, size);
|
||||
count += size;
|
||||
}
|
||||
|
||||
@Override public synchronized void reset() {
|
||||
super.reset();
|
||||
if (reserved) {
|
||||
buf = new byte[32];
|
||||
reserved = false;
|
||||
budget.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void close() { reset(); }
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package ai.openidea.jdbc;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/** Exercises the production frames with a supplied DuckDB JDBC distribution. */
|
||||
public final class DuckDbSelfTest {
|
||||
private static final class Bridge implements AutoCloseable {
|
||||
private final Process child;
|
||||
private final DataInputStream in;
|
||||
private final DataOutputStream out;
|
||||
private long id = 1;
|
||||
|
||||
Bridge(String java) throws IOException {
|
||||
child = SelfTest.start(java, true);
|
||||
in = new DataInputStream(child.getInputStream());
|
||||
out = new DataOutputStream(child.getOutputStream());
|
||||
}
|
||||
|
||||
SelfTest.Tagged request(int connection, int status, String... fields) throws IOException {
|
||||
long current = id++;
|
||||
SelfTest.sendOn(out, current, connection, fields);
|
||||
return SelfTest.expect(in, current, status);
|
||||
}
|
||||
|
||||
void open(String url) throws IOException {
|
||||
request(0, 1, "open", "org.duckdb.DuckDBDriver", url, "", "", "false");
|
||||
}
|
||||
|
||||
void execute(int connection, String sql) throws IOException {
|
||||
request(connection, 1, "query", sql, "0", "2");
|
||||
}
|
||||
|
||||
String value(int connection, String sql) throws IOException {
|
||||
var message = request(connection, 1, "query", sql, "0", "2");
|
||||
try (var value = new DataInputStream(new ByteArrayInputStream(message.data()))) {
|
||||
assert value.readBoolean();
|
||||
assert value.readInt() == 1;
|
||||
text(value); // Column label.
|
||||
text(value); // JDBC type.
|
||||
assert value.readBoolean();
|
||||
return text(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void close() throws Exception {
|
||||
try {
|
||||
out.close();
|
||||
if (!child.waitFor(5, TimeUnit.SECONDS))
|
||||
throw new AssertionError("JDBC process did not close its connections on EOF");
|
||||
assert child.exitValue() == 0 : new String(child.getErrorStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
} finally {
|
||||
if (child.isAlive()) child.destroyForcibly().waitFor();
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String text(DataInputStream in) throws IOException {
|
||||
int size = in.readInt();
|
||||
return size == -1 ? null : new String(in.readNBytes(size), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
var java = Path.of(System.getProperty("java.home"), "bin", "java").toString();
|
||||
try (var bridge = new Bridge(java)) {
|
||||
bridge.open("jdbc:duckdb:");
|
||||
bridge.request(1, 1, "open");
|
||||
bridge.request(2, 1, "open");
|
||||
bridge.execute(1, "CREATE TABLE durable(i INTEGER)");
|
||||
bridge.execute(1, "INSERT INTO durable VALUES (41)");
|
||||
assert bridge.value(2, "SELECT i FROM durable").equals("41");
|
||||
bridge.execute(1, "CREATE TEMP TABLE private_table(i INTEGER)");
|
||||
bridge.execute(1, "INSERT INTO private_table VALUES (7)");
|
||||
assert bridge.value(1, "SELECT i FROM private_table").equals("7");
|
||||
bridge.request(2, 0, "query", "SELECT i FROM private_table", "0", "2");
|
||||
|
||||
bridge.execute(1, "ATTACH ':memory:' AS attached_catalog");
|
||||
bridge.execute(1, "USE attached_catalog");
|
||||
assert bridge.value(1, "SELECT current_database()").equals("attached_catalog");
|
||||
assert !bridge.value(2, "SELECT current_database()").equals("attached_catalog");
|
||||
bridge.execute(1, "CREATE TABLE shared_catalog(i INTEGER)");
|
||||
bridge.execute(1, "INSERT INTO shared_catalog VALUES (9)");
|
||||
assert bridge.value(2, "SELECT i FROM attached_catalog.main.shared_catalog").equals("9");
|
||||
|
||||
bridge.request(1, 1, "close");
|
||||
assert bridge.value(2, "SELECT i FROM durable").equals("41");
|
||||
bridge.request(3, 1, "open");
|
||||
assert bridge.value(3, "SELECT i FROM attached_catalog.main.shared_catalog").equals("9");
|
||||
}
|
||||
|
||||
var fixture = Files.createTempDirectory("openidea-jdbc-duckdb-");
|
||||
var url = "jdbc:duckdb:" + fixture.resolve("fixture.duckdb");
|
||||
try {
|
||||
try (var bridge = new Bridge(java)) {
|
||||
bridge.open(url);
|
||||
bridge.request(1, 1, "open");
|
||||
bridge.request(2, 1, "open");
|
||||
bridge.execute(1, "CREATE TABLE durable(i INTEGER)");
|
||||
bridge.execute(1, "INSERT INTO durable VALUES (42)");
|
||||
assert bridge.value(2, "SELECT i FROM durable").equals("42");
|
||||
bridge.request(1, 1, "close");
|
||||
}
|
||||
try (var reopened = new Bridge(java)) {
|
||||
reopened.open(url);
|
||||
assert reopened.value(0, "SELECT i FROM durable").equals("42");
|
||||
}
|
||||
} finally {
|
||||
try (var paths = Files.walk(fixture)) {
|
||||
for (var path : paths.sorted(Comparator.reverseOrder()).toList()) Files.delete(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,21 @@ package ai.openidea.jdbc;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/** Drives the bridge over its actual pipes with a deterministic JDBC driver. */
|
||||
public class SelfTest {
|
||||
public static class Fixture implements Driver {
|
||||
private static final CountDownLatch releaseCancellation = new CountDownLatch(1);
|
||||
private static final String LARGE_CELL = "x".repeat(16 * 1024);
|
||||
private boolean readonly;
|
||||
private boolean dropped;
|
||||
private int changes;
|
||||
@@ -42,8 +47,11 @@ public class SelfTest {
|
||||
});
|
||||
return proxy(Connection.class, (p, m, a) -> switch (m.getName()) {
|
||||
case "setReadOnly" -> { readonly = (boolean) a[0]; yield null; }
|
||||
case "getMetaData" -> meta;
|
||||
case "close" -> null;
|
||||
case "getMetaData" -> {
|
||||
if (path.equals("fail-metadata")) throw new SQLException("private bootstrap detail");
|
||||
yield meta;
|
||||
}
|
||||
case "close" -> { System.err.println("connection closed"); yield null; }
|
||||
case "createStatement" -> statement();
|
||||
case "isClosed" -> false;
|
||||
case "isValid" -> !dropped;
|
||||
@@ -64,12 +72,43 @@ public class SelfTest {
|
||||
});
|
||||
}
|
||||
|
||||
static ResultSet largeRows(boolean fail) {
|
||||
int[] rows = {0};
|
||||
var metadata = proxy(ResultSetMetaData.class, (p, m, a) -> switch (m.getName()) {
|
||||
case "getColumnCount" -> 1;
|
||||
case "getColumnLabel" -> "payload";
|
||||
case "getColumnTypeName" -> "VARCHAR";
|
||||
case "getColumnType" -> Types.VARCHAR;
|
||||
default -> throw new SQLFeatureNotSupportedException();
|
||||
});
|
||||
return proxy(ResultSet.class, (p, m, a) -> switch (m.getName()) {
|
||||
case "next" -> {
|
||||
if (++rows[0] == 6 && fail) throw new SQLException("large result failed while reading");
|
||||
yield rows[0] <= 990;
|
||||
}
|
||||
case "getMetaData" -> metadata;
|
||||
case "getString" -> LARGE_CELL;
|
||||
case "close" -> null;
|
||||
default -> throw new SQLFeatureNotSupportedException();
|
||||
});
|
||||
}
|
||||
|
||||
Statement statement() {
|
||||
var stop = new CountDownLatch(1);
|
||||
var slowCancel = new AtomicBoolean();
|
||||
boolean[] failLargeRows = {false};
|
||||
return proxy(Statement.class, (p, m, a) -> switch (m.getName()) {
|
||||
case "execute" -> {
|
||||
String sql = (String) a[0];
|
||||
if (sql.equals("wait") || sql.equals("ignore cancel")) {
|
||||
if (sql.equals("large rows") || sql.equals("large error")) {
|
||||
failLargeRows[0] = sql.equals("large error");
|
||||
System.err.println("large query started");
|
||||
yield true;
|
||||
}
|
||||
if (sql.equals("write marker")) Files.writeString(started, "once\n", StandardOpenOption.APPEND);
|
||||
if (sql.equals("release cancel gate")) releaseCancellation.countDown();
|
||||
if (sql.equals("wait for cancel gate")) slowCancel.set(true);
|
||||
if (sql.equals("wait") || sql.equals("ignore cancel") || slowCancel.get()) {
|
||||
if (started != null) java.nio.file.Files.writeString(started, "started");
|
||||
System.err.println("statement started");
|
||||
if (sql.equals("ignore cancel")) Thread.sleep(60_000);
|
||||
@@ -81,7 +120,16 @@ public class SelfTest {
|
||||
changes++;
|
||||
yield false;
|
||||
}
|
||||
case "cancel" -> { stop.countDown(); yield null; }
|
||||
case "cancel" -> {
|
||||
if (slowCancel.get()) {
|
||||
System.err.println("cancel entered");
|
||||
if (!releaseCancellation.await(15, TimeUnit.SECONDS))
|
||||
throw new SQLException("cancel gate timed out");
|
||||
}
|
||||
stop.countDown();
|
||||
yield null;
|
||||
}
|
||||
case "getResultSet" -> largeRows(failLargeRows[0]);
|
||||
case "getUpdateCount" -> changes;
|
||||
case "close" -> null;
|
||||
default -> throw new SQLFeatureNotSupportedException();
|
||||
@@ -114,6 +162,236 @@ public class SelfTest {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static void sendOn(DataOutputStream out, long id, int connection, String... fields) throws IOException {
|
||||
out.writeLong(id);
|
||||
out.writeInt(connection);
|
||||
out.writeInt(fields.length);
|
||||
for (String field : fields) {
|
||||
byte[] data = field.getBytes(StandardCharsets.UTF_8);
|
||||
out.writeInt(data.length);
|
||||
out.write(data);
|
||||
}
|
||||
out.flush();
|
||||
}
|
||||
|
||||
record Tagged(long id, byte[] data) {
|
||||
int status() { return data.length == 0 ? -1 : data[0]; }
|
||||
}
|
||||
|
||||
static Tagged tagged(DataInputStream in) throws IOException {
|
||||
return new Tagged(in.readLong(), reply(in));
|
||||
}
|
||||
|
||||
static Tagged expect(DataInputStream in, long id, int status) throws IOException {
|
||||
var message = tagged(in);
|
||||
assert message.id() == id && message.status() == status
|
||||
: "Expected reply " + id + "/" + status + ", got " + message.id() + "/" + message.status();
|
||||
return message;
|
||||
}
|
||||
|
||||
static Process start(String java, boolean multiplex, String... jvmOptions) throws IOException {
|
||||
var command = new ArrayList<String>();
|
||||
command.add(java);
|
||||
command.addAll(List.of(jvmOptions));
|
||||
command.addAll(List.of("--enable-native-access=ALL-UNNAMED", "-cp", System.getProperty("java.class.path"),
|
||||
OpenIdeaJdbc.class.getName()));
|
||||
if (multiplex) command.add("--multiplex");
|
||||
return new ProcessBuilder(command).start();
|
||||
}
|
||||
|
||||
static void multiplex(String java) throws Exception {
|
||||
var child = start(java, true);
|
||||
try (var out = new DataOutputStream(child.getOutputStream());
|
||||
var in = new DataInputStream(child.getInputStream());
|
||||
var log = child.errorReader()) {
|
||||
sendOn(out, 100, 0, "open", Fixture.class.getName(), "jdbc:fixture:", "", "", "false");
|
||||
try {
|
||||
expect(in, 100, 1);
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError("The bridge did not accept the multiplex bootstrap frame", e);
|
||||
}
|
||||
sendOn(out, 101, 1, "open");
|
||||
expect(in, 101, 1);
|
||||
sendOn(out, 102, 2, "open");
|
||||
expect(in, 102, 1);
|
||||
sendOn(out, 103, 1, "query", "wait for cancel gate", "0", "2");
|
||||
assert log.lines().anyMatch("statement started"::equals);
|
||||
sendOn(out, 104, 1, "query", "overlap", "0", "2");
|
||||
expect(in, 104, 0);
|
||||
|
||||
sendOn(out, 103, 2); // Wrong connection must not cancel the active request.
|
||||
expect(in, 103, -1);
|
||||
sendOn(out, 105, 2, "query", "independent console", "0", "2");
|
||||
expect(in, 105, 1);
|
||||
sendOn(out, 103, 1);
|
||||
expect(in, 103, -1);
|
||||
assert log.lines().anyMatch("cancel entered"::equals);
|
||||
sendOn(out, 106, 0, "schemaColumns", "app");
|
||||
expect(in, 106, 1); // The driver is still withholding the cancellation response.
|
||||
sendOn(out, 107, 1, "close");
|
||||
expect(in, 107, 1);
|
||||
sendOn(out, 108, 1, "query", "retired", "0", "2");
|
||||
expect(in, 108, 0);
|
||||
sendOn(out, 109, 2, "query", "release cancel gate", "0", "2");
|
||||
var first = tagged(in);
|
||||
var second = tagged(in);
|
||||
var statuses = Map.of(first.id(), first.status(), second.id(), second.status());
|
||||
assert statuses.equals(Map.of(103L, 0, 109L, 1)) : statuses;
|
||||
assert log.lines().anyMatch("connection closed"::equals);
|
||||
|
||||
sendOn(out, 110, 2, "query", "after sibling close", "0", "2");
|
||||
expect(in, 110, 1);
|
||||
sendOn(out, 111, 0, "valid");
|
||||
assert new String(expect(in, 111, 1).data(), StandardCharsets.UTF_8).contains("true");
|
||||
} finally {
|
||||
child.destroyForcibly().waitFor();
|
||||
}
|
||||
}
|
||||
|
||||
static void capacity(String java) throws Exception {
|
||||
var child = start(java, true);
|
||||
try (var out = new DataOutputStream(child.getOutputStream());
|
||||
var in = new DataInputStream(child.getInputStream());
|
||||
var log = child.errorReader()) {
|
||||
sendOn(out, 200, 0, "open", Fixture.class.getName(), "jdbc:fixture:fail-metadata", "", "", "false");
|
||||
var failure = new String(expect(in, 200, 0).data(), StandardCharsets.UTF_8);
|
||||
assert failure.contains("JDBC connection failed") && !failure.contains("private bootstrap detail");
|
||||
assert log.lines().anyMatch("connection closed"::equals);
|
||||
sendOn(out, 201, 0, "open", Fixture.class.getName(), "jdbc:fixture:", "", "", "false");
|
||||
expect(in, 201, 1);
|
||||
|
||||
for (int i = 1; i <= 31; i++) {
|
||||
sendOn(out, 201 + i, i, "open");
|
||||
expect(in, 201 + i, 1);
|
||||
}
|
||||
sendOn(out, 300, 32, "open");
|
||||
var full = new String(expect(in, 300, 0).data(), StandardCharsets.UTF_8);
|
||||
assert full.contains("Close") && full.contains("try again") : full;
|
||||
sendOn(out, 301, 31, "query", "survives admission failure", "0", "2");
|
||||
expect(in, 301, 1);
|
||||
|
||||
sendOn(out, 302, 1, "close");
|
||||
expect(in, 302, 1);
|
||||
sendOn(out, 303, 1, "query", "retired", "0", "2");
|
||||
expect(in, 303, 0);
|
||||
assert log.lines().anyMatch("connection closed"::equals);
|
||||
boolean reopened = false;
|
||||
for (int attempt = 0; attempt < 20; attempt++) {
|
||||
int id = 33 + attempt;
|
||||
sendOn(out, 304 + attempt, id, "open");
|
||||
var response = tagged(in);
|
||||
assert response.id() == 304 + attempt;
|
||||
if (response.status() == 1) {
|
||||
reopened = true;
|
||||
break;
|
||||
}
|
||||
assert response.status() == 0;
|
||||
Thread.sleep(5);
|
||||
}
|
||||
assert reopened : "A closed console did not release its connection slot";
|
||||
sendOn(out, 330, 0, "valid");
|
||||
expect(in, 330, 1);
|
||||
} finally {
|
||||
child.destroyForcibly().waitFor();
|
||||
}
|
||||
}
|
||||
|
||||
static void brokenStreams(String java) throws Exception {
|
||||
var marker = Files.createTempFile("openidea-jdbc-write-", ".txt");
|
||||
try {
|
||||
for (boolean breakOutput : new boolean[]{false, true}) {
|
||||
Files.writeString(marker, "");
|
||||
var child = start(java, true);
|
||||
try (var out = new DataOutputStream(child.getOutputStream());
|
||||
var in = new DataInputStream(child.getInputStream());
|
||||
var log = child.errorReader()) {
|
||||
sendOn(out, 400, 0, "open", Fixture.class.getName(), "jdbc:fixture:" + marker, "", "", "false");
|
||||
expect(in, 400, 1);
|
||||
sendOn(out, 401, 1, "open");
|
||||
expect(in, 401, 1);
|
||||
if (breakOutput) in.close();
|
||||
sendOn(out, 402, 1, "query", "write marker", "0", "2");
|
||||
if (!breakOutput) {
|
||||
expect(in, 402, 1);
|
||||
out.writeLong(403);
|
||||
out.writeInt(1);
|
||||
out.writeInt(1);
|
||||
out.writeInt(8);
|
||||
out.writeByte(0); // A truncated field, not a clean EOF between frames.
|
||||
out.close();
|
||||
}
|
||||
assert child.waitFor(5, TimeUnit.SECONDS) : "Broken JDBC pipe did not terminate (stdout=" + breakOutput + ")";
|
||||
assert child.exitValue() != 0;
|
||||
long closed = log.lines().filter("connection closed"::equals).count();
|
||||
assert closed == 2 : "Broken stdout=" + breakOutput + " closed " + closed + " connections";
|
||||
assert Files.readAllLines(marker).equals(List.of("once")) : "JDBC write was replayed";
|
||||
} finally {
|
||||
child.destroyForcibly().waitFor();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
Files.delete(marker);
|
||||
}
|
||||
}
|
||||
|
||||
static void boundedReplies(String java) throws Exception {
|
||||
var child = start(java, true, "-Xmx192m");
|
||||
try (var out = new DataOutputStream(child.getOutputStream());
|
||||
var in = new DataInputStream(child.getInputStream());
|
||||
var log = child.errorReader()) {
|
||||
sendOn(out, 500, 0, "open", Fixture.class.getName(), "jdbc:fixture:", "", "", "false");
|
||||
expect(in, 500, 1);
|
||||
int largeQueries = 16;
|
||||
for (int i = 1; i <= largeQueries + 1; i++) {
|
||||
sendOn(out, 500 + i, i, "open");
|
||||
expect(in, 500 + i, 1);
|
||||
}
|
||||
for (int i = 1; i <= largeQueries; i++)
|
||||
sendOn(out, 600 + i, i, "query", "large rows", "0", "1000");
|
||||
for (int i = 0; i < largeQueries; i++)
|
||||
assert log.lines().anyMatch("large query started"::equals);
|
||||
sendOn(out, 700, largeQueries + 1, "query", "small reply", "0", "1");
|
||||
sendOn(out, 701, largeQueries + 1); // Stale cancel still produces its tagged acknowledgement.
|
||||
// Back up stdout while the workers assemble their responses. The parent
|
||||
// drains the payloads in place rather than retaining the test data.
|
||||
Thread.sleep(300);
|
||||
Set<Long> replies = new HashSet<>();
|
||||
int smallAt = -1, ackAt = -1;
|
||||
for (int i = 0; i < largeQueries + 2; i++) {
|
||||
long id = in.readLong();
|
||||
int length = in.readInt();
|
||||
assert replies.add(id);
|
||||
if (id == 701) {
|
||||
assert length == 0;
|
||||
ackAt = i;
|
||||
continue;
|
||||
}
|
||||
assert length > 0 && length <= OpenIdeaJdbc.LIMIT;
|
||||
assert in.readBoolean() : "JDBC result did not finish: " + id;
|
||||
in.skipNBytes(length - 1);
|
||||
if (id == 700) {
|
||||
assert length < 1024;
|
||||
smallAt = i;
|
||||
} else {
|
||||
assert id > 600 && id <= 600 + largeQueries && length > 15 * 1024 * 1024;
|
||||
}
|
||||
}
|
||||
assert smallAt >= 0 && smallAt < largeQueries + 1;
|
||||
assert ackAt >= 0 && ackAt < largeQueries + 1;
|
||||
sendOn(out, 702, 0, "valid");
|
||||
expect(in, 702, 1);
|
||||
sendOn(out, 703, 1, "query", "large error", "0", "1000");
|
||||
expect(in, 703, 0);
|
||||
sendOn(out, 704, 2, "query", "large rows", "0", "1000");
|
||||
assert in.readLong() == 704;
|
||||
int length = in.readInt();
|
||||
assert length > 15 * 1024 * 1024 && in.readBoolean();
|
||||
in.skipNBytes(length - 1); // The failed encoding released its reply reservation.
|
||||
} finally {
|
||||
child.destroyForcibly().waitFor();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
var boundary = new DataOutputStream(OutputStream.nullOutputStream());
|
||||
OpenIdeaJdbc.text(boundary, "x".repeat(OpenIdeaJdbc.LIMIT - 14));
|
||||
@@ -124,8 +402,7 @@ public class SelfTest {
|
||||
throw new AssertionError("Oversized reply accepted");
|
||||
} catch (IOException expected) {}
|
||||
var java = Path.of(System.getProperty("java.home"), "bin", "java").toString();
|
||||
var child = new ProcessBuilder(java, "-cp", System.getProperty("java.class.path"),
|
||||
OpenIdeaJdbc.class.getName()).start();
|
||||
var child = start(java, false);
|
||||
try (var out = new DataOutputStream(child.getOutputStream());
|
||||
var in = new DataInputStream(child.getInputStream());
|
||||
var log = child.errorReader()) {
|
||||
@@ -163,5 +440,9 @@ public class SelfTest {
|
||||
} finally {
|
||||
child.destroyForcibly().waitFor();
|
||||
}
|
||||
multiplex(java);
|
||||
capacity(java);
|
||||
brokenStreams(java);
|
||||
boundedReplies(java);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Заблокувати користувача