Skip to content

Commit

Permalink
[misc] coverage addition
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Feb 11, 2021
1 parent 1017797 commit 690c905
Show file tree
Hide file tree
Showing 21 changed files with 181 additions and 133 deletions.
2 changes: 0 additions & 2 deletions src/main/java/org/mariadb/jdbc/client/Client.java
Expand Up @@ -89,7 +89,5 @@ void readStreamingResults(

ExceptionFactory getExceptionFactory();

void reset(ExceptionFactory exceptionFactory);

HostAddress getHostAddress();
}
7 changes: 1 addition & 6 deletions src/main/java/org/mariadb/jdbc/client/ClientImpl.java
Expand Up @@ -317,7 +317,7 @@ public QueryPacket createSessionVariableQuery() {
}

// force client timezone to connection to ensure result of now(), ...
if (conf.timezone() != null && !"disable".equalsIgnoreCase(conf.timezone())) {
if (conf.timezone() == null || !"disable".equalsIgnoreCase(conf.timezone())) {
String timeZone =
(conf.timezone() != null) ? conf.timezone() : ZoneId.systemDefault().getId();
sb.append(",time_zone='").append(timeZone).append("'");
Expand Down Expand Up @@ -809,11 +809,6 @@ public ExceptionFactory getExceptionFactory() {
return exceptionFactory;
}

public void reset(ExceptionFactory exceptionFactory) {
this.exceptionFactory = exceptionFactory;
this.context.resetPrepareCache(new PrepareCache(conf.prepStmtCacheSize(), this));
}

public HostAddress getHostAddress() {
return hostAddress;
}
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/mariadb/jdbc/client/MultiPrimaryClient.java
Expand Up @@ -471,11 +471,6 @@ public ExceptionFactory getExceptionFactory() {
return currentClient.getExceptionFactory();
}

@Override
public void reset(ExceptionFactory exceptionFactory) {
currentClient.reset(exceptionFactory);
}

@Override
public HostAddress getHostAddress() {
return currentClient.getHostAddress();
Expand Down
Expand Up @@ -348,12 +348,6 @@ public ExceptionFactory getExceptionFactory() {
return super.getExceptionFactory();
}

@Override
public void reset(ExceptionFactory exceptionFactory) {
reconnectIfNeeded();
super.reset(exceptionFactory);
}

@Override
public HostAddress getHostAddress() {
reconnectIfNeeded();
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/org/mariadb/jdbc/client/context/BaseContext.java
Expand Up @@ -127,18 +127,10 @@ public PrepareCache getPrepareCache() {
return prepareCache;
}

public void resetPrepareCache(PrepareCache prepareCache) {
this.prepareCache = prepareCache;
}

public int getStateFlag() {
return stateFlag;
}

public void setStateFlag(int stateFlag) {
this.stateFlag = stateFlag;
}

public void addStateFlag(int state) {
stateFlag |= state;
}
Expand All @@ -147,12 +139,4 @@ public void saveRedo(ClientMessage msg) {}

public void saveRedo(ClientMessage[] msgs) {}

public TransactionSaver getTransactionSaver() {
return null;
}

@Override
public String toString() {
return "ConnectionContext{" + "threadId=" + threadId + ", version=" + version + '}';
}
}
8 changes: 3 additions & 5 deletions src/main/java/org/mariadb/jdbc/client/context/Context.java
Expand Up @@ -62,17 +62,15 @@ public interface Context {

PrepareCache getPrepareCache();

void resetPrepareCache(PrepareCache prepareCache);

int getStateFlag();

void setStateFlag(int stateFlag);

void addStateFlag(int state);

void saveRedo(ClientMessage msg);

void saveRedo(ClientMessage[] msgs);

TransactionSaver getTransactionSaver();
default TransactionSaver getTransactionSaver() {
return null;
}
}
Expand Up @@ -112,16 +112,11 @@ public static ResultSet createResultSet(
int len = bb.length;
if (len < 251) {
baos.write((byte) len);
} else if (len < 65536) {
baos.write((byte) 0xfc);
baos.write((byte) len);
baos.write((byte) (len >>> 8));
} else {
// assumption : len < 16777216
baos.write((byte) 0xfd);
// assume length cannot be > 65536
baos.write((byte) 0xfc);
baos.write((byte) len);
baos.write((byte) (len >>> 8));
baos.write((byte) (len >>> 16));
}
baos.write(bb, 0, bb.length);
} else {
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/org/mariadb/jdbc/client/result/Result.java
Expand Up @@ -148,7 +148,7 @@ protected boolean readNext() throws SQLException, IOException {
// continue reading rows

default:
if (dataSize + 1 >= data.length) {
if (dataSize + 1 > data.length) {
growDataArray();
}
data[dataSize++] = buf;
Expand Down Expand Up @@ -233,17 +233,14 @@ public void closeFromStmtClose() throws SQLException {

public void abort() throws SQLException {
this.closed = true;
if (closeOnCompletion) {
statement.close();
}
}

protected byte[] getCurrentRowData() {
return data[0];
}

protected void addRowData(byte[] buf) {
if (dataSize + 1 >= data.length) {
if (dataSize + 1 > data.length) {
growDataArray();
}
data[dataSize++] = buf;
Expand Down
Expand Up @@ -267,12 +267,9 @@ public String getColumnTypeName(final int column) throws SQLException {
* @throws SQLException if a database access error occurs or in case of wrong index
*/
public boolean isReadOnly(final int column) throws SQLException {
if (column >= 1 && column <= fieldPackets.length) {
ColumnDefinitionPacket ci = getColumn(column);
return (ci.getTable() == null || ci.getTable().isEmpty())
&& (ci.getColumn() == null || ci.getColumn().isEmpty());
}
throw exceptionFactory.create(String.format("no column with index %s", column));
ColumnDefinitionPacket ci = getColumn(column);
return (ci.getTable() == null || ci.getTable().isEmpty())
&& (ci.getColumn() == null || ci.getColumn().isEmpty());
}

/**
Expand Down Expand Up @@ -316,7 +313,7 @@ private ColumnDefinitionPacket getColumn(int column) throws SQLException {
if (column >= 1 && column <= fieldPackets.length) {
return fieldPackets[column - 1];
}
throw exceptionFactory.create("No such column");
throw exceptionFactory.create(String.format("wrong column index %s", column));
}

/**
Expand Down
Expand Up @@ -174,11 +174,11 @@ private void retrieveBuffer() throws IOException {
readOffset += count;
} while (remaining > 0);

if (logger.isTraceEnabled()) {
logger.trace(
"read compress: \n{}",
LoggerHelper.hex(header, intermediaryBuf, 0, intermediaryBuf.length, 1000));
}
// if (logger.isTraceEnabled()) {
// logger.trace(
// "read compress: \n{}",
// LoggerHelper.hex(header, intermediaryBuf, 0, intermediaryBuf.length, 1000));
// }

if (compressed) {
buf = new byte[packetLength];
Expand Down
Expand Up @@ -130,9 +130,9 @@ private void writeSocket(boolean end) throws IOException {
buf[5] = 0;
buf[6] = 0;

if (logger.isTraceEnabled()) {
logger.trace("send compress: \n{}", LoggerHelper.hex(buf, 0, pos, 1000));
}
// if (logger.isTraceEnabled()) {
// logger.trace("send compress: \n{}", LoggerHelper.hex(buf, 0, pos, 1000));
// }
out.write(buf, 0, pos);

} else {
Expand Down Expand Up @@ -161,11 +161,11 @@ private void writeSocket(boolean end) throws IOException {

out.write(header, 0, 7);
out.write(compressedBytes, 0, compressLen);
if (logger.isTraceEnabled()) {
logger.trace(
"send compress: \n{}",
LoggerHelper.hex(header, compressedBytes, 0, compressLen, 1000));
}
// if (logger.isTraceEnabled()) {
// logger.trace(
// "send compress: \n{}",
// LoggerHelper.hex(header, compressedBytes, 0, compressLen, 1000));
// }
}
}

Expand Down
Expand Up @@ -243,7 +243,7 @@ public ReadableByteBuf readReadablePacket(boolean reUsable, boolean traceEnable)

if (traceEnable) {
logger.trace(
"read: {}{}",
"read: {}\n{}",
serverThreadLog,
LoggerHelper.hex(
header, rawBytes, currentbufLength, packetLength, maxQuerySizeToLog));
Expand Down Expand Up @@ -359,7 +359,7 @@ public byte[] readPacket(boolean reUsable, boolean traceEnable) throws IOExcepti

if (traceEnable) {
logger.trace(
"read: {}{}",
"read: {}\n{}",
serverThreadLog,
LoggerHelper.hex(
header, rawBytes, currentbufLength, packetLength, maxQuerySizeToLog));
Expand Down
Expand Up @@ -64,6 +64,7 @@ public void testSessionVariable() throws SQLException {
assertEquals(5, rs.getInt(1));
assertFalse(rs.next());
assertFalse(stmt.getMoreResults());
rs.clearWarnings();
}

try (Connection connection =
Expand Down
Expand Up @@ -741,13 +741,16 @@ private int getMaxAllowedPacket() throws SQLException {

@Test
public void skippingRes() throws SQLException {
Assumptions.assumeTrue(getMaxAllowedPacket() > 35_000_000);
int maxAllowedPacket = getMaxAllowedPacket();
Assumptions.assumeTrue(maxAllowedPacket > 35_000_000);
skippingRes(sharedConn);
skippingRes(sharedConnBinary);
try (Connection compressText = createCon("useCompression")) {
try (Connection compressText =
createCon("useCompression&maxAllowedPacket=" + maxAllowedPacket)) {
skippingRes(compressText);
}
try (Connection compressBinary = createCon("useCompression&useServerPrepStmts")) {
try (Connection compressBinary =
createCon("useCompression&useServerPrepStmts&maxAllowedPacket=" + maxAllowedPacket)) {
skippingRes(compressBinary);
}
}
Expand Down

0 comments on commit 690c905

Please sign in to comment.