Skip to content

Commit 0e8c7a0

Browse files
author
diego Dupin
committed
[misc] coverage addition + correcting development combination SKIP META with EOF
1 parent e3f0395 commit 0e8c7a0

21 files changed

+201
-298
lines changed

.travis.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ jobs:
4444
- env: srv=mariadb v=10.2 local=1
4545
- env: srv=mariadb v=10.3 local=1
4646
- env: srv=mariadb v=10.4 local=1
47-
- env: srv=mariadb v=10.6 local=1
48-
- env: srv=mariadb v=10.5 packet=40
49-
- env: srv=mariadb v=10.5 packet=8
50-
- env: srv=mariadb v=10.5 BENCH=1
47+
- env: srv=mariadb v=10.5 local=1
48+
- env: srv=mariadb v=10.6 packet=40
49+
- env: srv=mariadb v=10.6 packet=8
50+
- env: srv=mariadb v=10.6 BENCH=1
5151
- if: type = push AND fork = false
5252
env: srv=maxscale
5353
- if: type = push AND fork = false
5454
env: srv=build v=10.6
55+
- if: type = push AND fork = false
56+
env: srv=mariadb-es v=10.6
5557
- if: type = push AND fork = false
5658
env: srv=mysql v=5.7
5759
- if: type = push AND fork = false

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<logback.version>1.3.0-alpha10</logback.version>
2424
<jacoco.version>0.8.7</jacoco.version>
2525
<waffle-jna.version>3.0.0</waffle-jna.version>
26-
<mysql-connector-java.version>8.0.27</mysql-connector-java.version><!--5.1.49-->
26+
<mysql-connector-java.version>8.0.27</mysql-connector-java.version>
2727
</properties>
2828

2929
<licenses>

src/main/java/org/mariadb/jdbc/client/impl/ConnectionHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ public static long initializeClientCapabilities(
169169
}
170170

171171
// useEof is a technical option
172-
boolean useEof =
173-
Boolean.parseBoolean(configuration.nonMappedOptions().getProperty("useEof", "true"));
174-
if ((serverCapabilities & Capabilities.CLIENT_DEPRECATE_EOF) != 0 && useEof) {
172+
boolean deprecateEof =
173+
Boolean.parseBoolean(configuration.nonMappedOptions().getProperty("deprecateEof", "true"));
174+
if ((serverCapabilities & Capabilities.CLIENT_DEPRECATE_EOF) != 0 && deprecateEof) {
175175
capabilities |= Capabilities.CLIENT_DEPRECATE_EOF;
176176
}
177177

src/main/java/org/mariadb/jdbc/client/socket/impl/CompressInputStream.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,19 @@ public int read(byte[] b, int off, int len) throws IOException {
7878
}
7979

8080
int totalReads = 0;
81-
while (true) {
8281

82+
do {
8383
if (end - pos <= 0) {
8484
retrieveBuffer();
8585
}
86-
8786
// copy internal value to buf.
8887
int copyLength = Math.min(len - totalReads, end - pos);
8988
System.arraycopy(buf, pos, b, off + totalReads, copyLength);
9089
pos += copyLength;
9190
totalReads += copyLength;
91+
} while (totalReads < len && super.available() > 0);
9292

93-
if (totalReads >= len || super.available() <= 0) {
94-
return totalReads;
95-
}
96-
}
93+
return totalReads;
9794
}
9895

9996
private void retrieveBuffer() throws IOException {

src/main/java/org/mariadb/jdbc/client/socket/impl/CompressOutputStream.java

Lines changed: 35 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -12,64 +12,15 @@
1212

1313
public class CompressOutputStream extends OutputStream {
1414
private static final int MIN_COMPRESSION_SIZE = 1536; // TCP-IP single packet
15-
private static final int SMALL_BUFFER_SIZE = 8192;
16-
private static final int MEDIUM_BUFFER_SIZE = 128 * 1024;
17-
private static final int LARGE_BUFFER_SIZE = 1024 * 1024;
18-
private static final int MAX_PACKET_LENGTH = 0x00ffffff + 7;
19-
private int maxPacketLength = MAX_PACKET_LENGTH;
2015
private final OutputStream out;
2116
private final MutableInt sequence;
22-
private byte[] buf = new byte[SMALL_BUFFER_SIZE];
23-
private int pos = 7;
17+
private final byte[] header = new byte[7];
2418

2519
public CompressOutputStream(OutputStream out, MutableInt compressionSequence) {
2620
this.out = out;
2721
this.sequence = compressionSequence;
2822
}
2923

30-
public void setMaxAllowedPacket(int maxAllowedPacket) {
31-
maxPacketLength = Math.min(MAX_PACKET_LENGTH, maxAllowedPacket + 7);
32-
}
33-
34-
/**
35-
* buf growing use 4 size only to avoid creating/copying that are expensive operations. possible
36-
* size
37-
*
38-
* <ol>
39-
* <li>SMALL_buf_SIZE = 8k (default)
40-
* <li>MEDIUM_buf_SIZE = 128k
41-
* <li>LARGE_buf_SIZE = 1M
42-
* <li>getMaxPacketLength = 16M (+ 4 if using no compression)
43-
* </ol>
44-
*
45-
* @param len length to add
46-
*/
47-
private void growBuffer(int len) {
48-
int bufLength = buf.length;
49-
int newCapacity;
50-
if (bufLength == SMALL_BUFFER_SIZE) {
51-
if (len + pos < MEDIUM_BUFFER_SIZE) {
52-
newCapacity = MEDIUM_BUFFER_SIZE;
53-
} else if (len + pos < LARGE_BUFFER_SIZE) {
54-
newCapacity = LARGE_BUFFER_SIZE;
55-
} else {
56-
newCapacity = maxPacketLength;
57-
}
58-
} else if (bufLength == MEDIUM_BUFFER_SIZE) {
59-
if (len + pos < LARGE_BUFFER_SIZE) {
60-
newCapacity = LARGE_BUFFER_SIZE;
61-
} else {
62-
newCapacity = maxPacketLength;
63-
}
64-
} else {
65-
newCapacity = maxPacketLength;
66-
}
67-
68-
byte[] newBuf = new byte[newCapacity];
69-
System.arraycopy(buf, 0, newBuf, 0, pos);
70-
buf = newBuf;
71-
}
72-
7324
/**
7425
* Writes <code>len</code> bytes from the specified byte array starting at offset <code>off</code>
7526
* to this output stream. The general contract for <code>write(b, off, len)</code> is that some
@@ -95,77 +46,47 @@ private void growBuffer(int len) {
9546
*/
9647
@Override
9748
public void write(byte[] b, int off, int len) throws IOException {
98-
if (pos + len >= buf.length) growBuffer(len);
99-
if (pos + len >= buf.length) {
100-
// fill buffer, then flush
101-
while (len > buf.length - pos) {
102-
int writeLen = buf.length - pos;
103-
System.arraycopy(b, off, buf, pos, writeLen);
104-
pos += writeLen;
105-
writeSocket(false);
106-
off += writeLen;
107-
len -= writeLen;
108-
}
109-
}
110-
// enough place in buffer.
111-
System.arraycopy(b, off, buf, pos, len);
112-
pos += len;
113-
}
114-
115-
private void writeSocket(boolean end) throws IOException {
116-
if (pos > 7) {
117-
if (pos < MIN_COMPRESSION_SIZE) {
118-
// *******************************************************************************
119-
// small packet, no compression
120-
// *******************************************************************************
121-
122-
buf[0] = (byte) (pos - 7);
123-
buf[1] = (byte) ((pos - 7) >>> 8);
124-
buf[2] = 0;
125-
buf[3] = sequence.incrementAndGet();
126-
buf[4] = 0;
127-
buf[5] = 0;
128-
buf[6] = 0;
129-
130-
out.write(buf, 0, pos);
49+
if (len < MIN_COMPRESSION_SIZE) {
50+
// *******************************************************************************
51+
// small packet, no compression
52+
// *******************************************************************************
53+
54+
header[0] = (byte) len;
55+
header[1] = (byte) (len >>> 8);
56+
header[2] = 0;
57+
header[3] = sequence.incrementAndGet();
58+
header[4] = 0;
59+
header[5] = 0;
60+
header[6] = 0;
61+
out.write(header, 0, 7);
62+
out.write(b, off, len);
13163

132-
} else {
133-
134-
// *******************************************************************************
135-
// compressing packet
136-
// *******************************************************************************
137-
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
138-
try (DeflaterOutputStream deflater = new DeflaterOutputStream(baos)) {
139-
deflater.write(buf, 7, pos - 7);
140-
deflater.finish();
141-
}
64+
} else {
14265

143-
byte[] compressedBytes = baos.toByteArray();
66+
// *******************************************************************************
67+
// compressing packet
68+
// *******************************************************************************
69+
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
70+
try (DeflaterOutputStream deflater = new DeflaterOutputStream(baos)) {
71+
deflater.write(b, off, len);
72+
deflater.finish();
73+
}
14474

145-
int compressLen = compressedBytes.length;
75+
byte[] compressedBytes = baos.toByteArray();
14676

147-
byte[] header = new byte[7];
148-
header[0] = (byte) compressLen;
149-
header[1] = (byte) (compressLen >>> 8);
150-
header[2] = (byte) (compressLen >>> 16);
151-
header[3] = sequence.incrementAndGet();
152-
header[4] = (byte) (pos - 7);
153-
header[5] = (byte) ((pos - 7) >>> 8);
154-
header[6] = (byte) ((pos - 7) >>> 16);
77+
int compressLen = compressedBytes.length;
15578

156-
out.write(header, 0, 7);
157-
out.write(compressedBytes, 0, compressLen);
158-
}
159-
}
79+
header[0] = (byte) compressLen;
80+
header[1] = (byte) (compressLen >>> 8);
81+
header[2] = (byte) (compressLen >>> 16);
82+
header[3] = sequence.incrementAndGet();
83+
header[4] = (byte) len;
84+
header[5] = (byte) (len >>> 8);
85+
header[6] = (byte) (len >>> 16);
16086

161-
if (end) {
162-
// if buf is big, and last query doesn't use at least half of it, resize buf to default
163-
// value
164-
if (buf.length > SMALL_BUFFER_SIZE && pos * 2 < buf.length) {
165-
buf = new byte[SMALL_BUFFER_SIZE];
166-
}
87+
out.write(header, 0, 7);
88+
out.write(compressedBytes, 0, compressLen);
16789
}
168-
pos = 7;
16990
}
17091
}
17192

@@ -186,7 +107,6 @@ private void writeSocket(boolean end) throws IOException {
186107
*/
187108
@Override
188109
public void flush() throws IOException {
189-
writeSocket(true);
190110
out.flush();
191111
sequence.set((byte) -1);
192112
}

src/main/java/org/mariadb/jdbc/client/socket/impl/NamedPipeSocket.java

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ public void close() throws IOException {
3333
}
3434
}
3535

36-
@Override
37-
public void connect(SocketAddress endpoint) throws IOException {
38-
connect(endpoint, 0);
39-
}
40-
4136
/**
4237
* Name pipe connection.
4338
*
@@ -46,12 +41,9 @@ public void connect(SocketAddress endpoint) throws IOException {
4641
* @throws IOException exception
4742
*/
4843
public void connect(SocketAddress endpoint, int timeout) throws IOException {
49-
String filename;
50-
if (host == null || host.equals("localhost")) {
51-
filename = "\\\\.\\pipe\\" + name;
52-
} else {
53-
filename = "\\\\" + host + "\\pipe\\" + name;
54-
}
44+
String filename =
45+
String.format(
46+
"\\\\%s\\pipe\\%s", (host == null || host.equals("localhost")) ? "." : host, name);
5547

5648
// use a default timeout of 100ms if no timeout set.
5749
int usedTimeout = timeout == 0 ? 100 : timeout;
@@ -115,14 +107,7 @@ public void write(byte[] bytes, int off, int len) throws IOException {
115107
}
116108

117109
@Override
118-
public void write(int value) throws IOException {
119-
file.write(value);
120-
}
121-
122-
@Override
123-
public void write(byte[] bytes) throws IOException {
124-
file.write(bytes);
125-
}
110+
public void write(int value) {}
126111
};
127112
}
128113

@@ -142,14 +127,6 @@ public void setKeepAlive(boolean bool) {
142127
// do nothing
143128
}
144129

145-
public void setReceiveBufferSize(int size) {
146-
// do nothing
147-
}
148-
149-
public void setSendBufferSize(int size) {
150-
// do nothing
151-
}
152-
153130
public void setSoLinger(boolean bool, int value) {
154131
// do nothing
155132
}
@@ -159,10 +136,6 @@ public void setSoTimeout(int timeout) {
159136
// do nothing
160137
}
161138

162-
public void shutdownInput() {
163-
// do nothing
164-
}
165-
166139
public void shutdownOutput() {
167140
// do nothing
168141
}

src/main/java/org/mariadb/jdbc/client/socket/impl/PacketWriter.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,6 @@ public boolean throwMaxAllowedLength(int length) {
702702
public void setMaxAllowedPacket(int maxAllowedPacket) {
703703
this.maxAllowedPacket = maxAllowedPacket;
704704
maxPacketLength = Math.min(MAX_PACKET_LENGTH, maxAllowedPacket + 4);
705-
if (out instanceof CompressOutputStream) {
706-
((CompressOutputStream) out).setMaxAllowedPacket(maxAllowedPacket);
707-
}
708705
}
709706

710707
public void permitTrace(boolean permitTrace) {

0 commit comments

Comments
 (0)