Skip to content

Commit

Permalink
[misc] ensure timeout test are not stalling
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jul 1, 2021
1 parent 1a5bec3 commit bbdb24f
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 67 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![Maven Central][maven-image]][maven-url]
[![Test Build][travis-image]][travis-url]
[![License][license-image]][license-url]

[![codecov][codecov-image]][codecov-url]

**Non-blocking MariaDB and MySQL client.**

Expand Down Expand Up @@ -107,6 +107,7 @@ Basic example:
| **`prepareCacheSize`** | if useServerPrepStmts = true, cache the prepared informations in a LRU cache to avoid re-preparation of command. Next use of that command, only prepared identifier and parameters (if any) will be sent to server. This mainly permit for server to avoid reparsing query. |*int* |256 |
| **`pamOtherPwd`** | Permit to provide additional password for PAM authentication with multiple authentication step. If multiple passwords, value must be URL encoded.|*string* | |
| **`autocommit`** | Set default autocommit value on connection initialization" |*boolean* | true |
| **`tinyInt1isBit`** | Convert Bit(1)/TINYINT(1) default to boolean type |*boolean* | true |

## Roadmap

Expand All @@ -127,3 +128,5 @@ To file an issue or follow the development, see [JIRA](https://jira.mariadb.org/
[maven-url]:https://maven-badges.herokuapp.com/maven-central/org.mariadb/r2dbc-mariadb
[license-image]:https://img.shields.io/badge/License-Apache%202.0-blue.svg
[license-url]:https://opensource.org/licenses/Apache-2.0
[codecov-image]:https://codecov.io/gh/mariadb-corporation/mariadb-connector-r2dbc/branch/master/graph/badge.svg?token=8fIhax7q23
[codecov-url]:https://codecov.io/gh/mariadb-corporation/mariadb-connector-r2dbc
105 changes: 61 additions & 44 deletions src/test/java/org/mariadb/r2dbc/integration/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void connectionError() throws Exception {
&& !"skysql".equals(System.getenv("srv"))
&& !"skysql-ha".equals(System.getenv("srv")));

disableLog();
//disableLog();
MariadbConnection connection = createProxyCon();
try {
proxy.stop();
Expand All @@ -105,7 +105,7 @@ void connectionError() throws Exception {
"real msg:" + t.getMessage());
} finally {
Thread.sleep(100);
reInitLog();
//reInitLog();
}
}

Expand All @@ -116,7 +116,7 @@ void multipleCommandStack() throws Exception {
&& !"skysql".equals(System.getenv("srv"))
&& !"skysql-ha".equals(System.getenv("srv")));

disableLog();
//disableLog();
MariadbConnection connection = createProxyCon();
Runnable runnable = () -> proxy.stop();
Thread th = new Thread(runnable);
Expand All @@ -141,7 +141,7 @@ void multipleCommandStack() throws Exception {
"real msg:" + t.getCause().getMessage());
} finally {
Thread.sleep(100);
reInitLog();
//reInitLog();
proxy.forceClose();
}
}
Expand All @@ -152,11 +152,11 @@ void connectionWithoutErrorOnClose() throws Exception {
!"maxscale".equals(System.getenv("srv"))
&& !"skysql".equals(System.getenv("srv"))
&& !"skysql-ha".equals(System.getenv("srv")));
disableLog();
//disableLog();
MariadbConnection connection = createProxyCon();
proxy.stop();
connection.close().block();
reInitLog();
//reInitLog();
}

@Test
Expand All @@ -165,7 +165,7 @@ void connectionDuringError() throws Exception {
!"maxscale".equals(System.getenv("srv"))
&& !"skysql".equals(System.getenv("srv"))
&& !"skysql-ha".equals(System.getenv("srv")));
disableLog();
//disableLog();
MariadbConnection connection = createProxyCon();
new Timer()
.schedule(
Expand All @@ -177,29 +177,31 @@ public void run() {
},
200);

try {
connection
.createStatement(
"select * from information_schema.columns as c1, "
+ "information_schema.tables, information_schema.tables as t2")
.execute()
.flatMap(r -> r.map((rows, meta) -> ""))
.blockLast();
Assertions.fail("must have throw exception");
} catch (Throwable t) {
Assertions.assertEquals(R2dbcNonTransientResourceException.class, t.getClass());
Assertions.assertTrue(
t.getMessage().contains("Connection is close. Cannot send anything")
|| t.getMessage().contains("Connection unexpectedly closed")
|| t.getMessage().contains("Connection unexpected error"),
"real msg:" + t.getMessage());
connection
.validate(ValidationDepth.LOCAL)
.as(StepVerifier::create)
.expectNext(Boolean.FALSE)
.verifyComplete();
reInitLog();
}
assertTimeout(Duration.ofSeconds(2), () -> {
try {
connection
.createStatement(
"select * from information_schema.columns as c1, "
+ "information_schema.tables, information_schema.tables as t2")
.execute()
.flatMap(r -> r.map((rows, meta) -> ""))
.blockLast();
Assertions.fail("must have throw exception");
} catch (Throwable t) {
Assertions.assertEquals(R2dbcNonTransientResourceException.class, t.getClass());
Assertions.assertTrue(
t.getMessage().contains("Connection is close. Cannot send anything")
|| t.getMessage().contains("Connection unexpectedly closed")
|| t.getMessage().contains("Connection unexpected error"),
"real msg:" + t.getMessage());
connection
.validate(ValidationDepth.LOCAL)
.as(StepVerifier::create)
.expectNext(Boolean.FALSE)
.verifyComplete();
//reInitLog();
}
});
}

@Test
Expand Down Expand Up @@ -452,7 +454,7 @@ void multiThreading() throws Throwable {

@Test
void multiThreadingSameConnection() throws Throwable {
disableLog();
//disableLog();
try {
AtomicInteger completed = new AtomicInteger(0);
ThreadPoolExecutor scheduler =
Expand All @@ -469,7 +471,7 @@ void multiThreadingSameConnection() throws Throwable {
Assertions.assertEquals(100, completed.get());
} finally {
Thread.sleep(100);
reInitLog();
//reInitLog();
}
}

Expand Down Expand Up @@ -517,8 +519,8 @@ void sessionVariables() throws Exception {
(row, metadata) -> {
Assertions.assertEquals(row.get(0, BigInteger.class).intValue(), 2147483);
Assertions.assertEquals(row.get(1, BigInteger.class).intValue(), 60);
Assertions.assertFalse(row.get(0, BigInteger.class).equals(res[0]));
Assertions.assertFalse(row.get(1, BigInteger.class).equals(res[1]));
Assertions.assertNotEquals(row.get(0, BigInteger.class).intValue(), res[0].intValue());
Assertions.assertNotEquals(row.get(1, BigInteger.class).intValue(), res[1].intValue());
return 0;
}))
.blockLast();
Expand Down Expand Up @@ -835,7 +837,7 @@ public void initialIsolationLevel() {
}

@Test
public void errorOnConnection() {
public void errorOnConnection() throws Throwable {
BigInteger maxConn =
sharedConn
.createStatement("select @@max_connections")
Expand Down Expand Up @@ -865,6 +867,7 @@ public void errorOnConnection() {
}
Assertions.assertNotNull(expected);
Assertions.assertTrue(expected.getMessage().contains("Too many connections"));
Thread.sleep(1000);
}

@Test
Expand All @@ -887,17 +890,31 @@ void killedConnection() {
};
Thread thread = new Thread(runnable);
thread.start();
assertThrows(
R2dbcNonTransientResourceException.class,
() ->
connection
assertTimeout(Duration.ofSeconds(2), () -> {
try {
connection
.createStatement(
"select * from information_schema.columns as c1, "
+ "information_schema.tables, "
+ "information_schema.tables as t2")
"select * from information_schema.columns as c1, "
+ "information_schema.tables, information_schema.tables as t2")
.execute()
.blockLast(),
"Connection unexpectedly closed");
.flatMap(r -> r.map((rows, meta) -> ""))
.blockLast();
Assertions.fail("must have throw exception");
} catch (Throwable t) {
Assertions.assertEquals(R2dbcNonTransientResourceException.class, t.getClass());
Assertions.assertTrue(
t.getMessage().contains("Connection is close. Cannot send anything")
|| t.getMessage().contains("Connection unexpectedly closed")
|| t.getMessage().contains("Connection unexpected error"),
"real msg:" + t.getMessage());
connection
.validate(ValidationDepth.LOCAL)
.as(StepVerifier::create)
.expectNext(Boolean.FALSE)
.verifyComplete();
//reInitLog();
}
});
connection
.validate(ValidationDepth.LOCAL)
.as(StepVerifier::create)
Expand Down
54 changes: 32 additions & 22 deletions src/test/java/org/mariadb/r2dbc/integration/ResultsetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
import java.sql.SQLException;
import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;

import org.junit.jupiter.api.*;
import org.mariadb.r2dbc.BaseConnectionTest;
import org.mariadb.r2dbc.api.MariadbConnection;
import org.mariadb.r2dbc.api.MariadbStatement;
Expand All @@ -34,6 +33,23 @@
public class ResultsetTest extends BaseConnectionTest {
private static String vals = "azertyuiopqsdfghjklmwxcvbn";

@BeforeAll
public static void before2() {
dropAll();
sharedConn
.createStatement(
"CREATE TABLE prepare3 (t1 LONGTEXT, t2 LONGTEXT, t3 LONGTEXT, t4 LONGTEXT, t5 varchar(10))")
.execute()
.blockLast();
}

@AfterAll
public static void dropAll() {
sharedConn.createStatement("DROP TABLE prepare3").execute().blockLast();
}



@Test
void multipleResultSet() {
sharedConn
Expand Down Expand Up @@ -255,12 +271,13 @@ void getIndexToLow(MariadbConnection connection) {
private String generateLongText(int len) {
int leftLimit = 97; // letter 'a'
int rightLimit = 122; // letter 'z'
Random random = new Random();
return random
.ints(leftLimit, leftLimit + 1) // rightLimit + 1)
.limit(len)
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
.toString();
StringBuilder sb = new StringBuilder(len);
Random random = new Random();

for (int i = 0; i < len; i++) {
sb.appendCodePoint(leftLimit + random.nextInt(rightLimit - leftLimit));
}
return sb.toString();
}

@Test
Expand All @@ -272,22 +289,15 @@ public void skippingRes() throws SQLException {
.flatMap(r -> r.map((row, metadata) -> row.get(0, BigInteger.class)))
.blockLast();
Assumptions.assumeTrue(maxAllowedPacket.intValue() > 35_000_000);
sharedConn.createStatement("DROP TABLE IF EXISTS prepare3").execute().blockLast();
sharedConn
.createStatement(
"CREATE TABLE prepare3 (t1 LONGTEXT, t2 LONGTEXT, t3 LONGTEXT, t4 LONGTEXT, t5 varchar(10))")
.execute()
.blockLast();
skippingRes(sharedConn);
skippingRes(sharedConnPrepare);
String longText = generateLongText(20_000_000);
String mediumText = generateLongText(10_000_000);
String smallIntText = generateLongText(60_000);
skippingRes(sharedConn, longText, mediumText, smallIntText);
skippingRes(sharedConnPrepare, longText, mediumText, smallIntText);
}

private void skippingRes(MariadbConnection con) {
private void skippingRes(MariadbConnection con, String longText, String mediumText, String smallIntText) {
con.createStatement("TRUNCATE prepare3").execute().blockLast();
String longText = generateLongText(20_000_000);
String mediumText = generateLongText(10_000_000);
String smallIntText = generateLongText(60_000);

con.createStatement("INSERT INTO prepare3 values (?,?,?,?,?)")
.bind(0, longText)
.bind(1, mediumText)
Expand Down

0 comments on commit bbdb24f

Please sign in to comment.