aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/io/trygvis/test/DbUtil.java7
-rw-r--r--src/test/java/io/trygvis/test/PlainJavaExample.java26
-rwxr-xr-xsrc/test/resources/logback.xml6
3 files changed, 31 insertions, 8 deletions
diff --git a/src/test/java/io/trygvis/test/DbUtil.java b/src/test/java/io/trygvis/test/DbUtil.java
index 2362e65..a2c41d3 100644
--- a/src/test/java/io/trygvis/test/DbUtil.java
+++ b/src/test/java/io/trygvis/test/DbUtil.java
@@ -5,7 +5,6 @@ import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy;
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
import javax.sql.DataSource;
-
import java.io.PrintWriter;
import java.sql.SQLException;
@@ -34,7 +33,7 @@ public class DbUtil {
ds.setDefaultAutoCommit(false);
ds.setIdleConnectionTestPeriodInSeconds(60);
ds.setIdleMaxAgeInSeconds(240);
- ds.setMaxConnectionsPerPartition(1);
+ ds.setMaxConnectionsPerPartition(2);
ds.setMinConnectionsPerPartition(0);
ds.setPartitionCount(1);
ds.setAcquireIncrement(1);
@@ -43,6 +42,10 @@ public class DbUtil {
ds.setStatisticsEnabled(true);
ds.setLogStatementsEnabled(true);
ds.setLogWriter(new PrintWriter(System.err));
+ return ds;
+ }
+
+ public static DataSource springifyDataSource(DataSource ds) {
return new TransactionAwareDataSourceProxy(new LazyConnectionDataSourceProxy(ds));
}
}
diff --git a/src/test/java/io/trygvis/test/PlainJavaExample.java b/src/test/java/io/trygvis/test/PlainJavaExample.java
index b09d3e9..488ee35 100644
--- a/src/test/java/io/trygvis/test/PlainJavaExample.java
+++ b/src/test/java/io/trygvis/test/PlainJavaExample.java
@@ -16,6 +16,7 @@ import java.util.List;
import java.util.Random;
import static io.trygvis.test.DbUtil.createDataSource;
+import static java.lang.System.currentTimeMillis;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
@@ -58,7 +59,7 @@ public class PlainJavaExample {
System.out.println("a + b = " + a + " + " + b + " = " + (a + b));
- if(r.nextInt(3) == 0) {
+ if (r.nextInt(3) == 0) {
return singletonList(task.childTask(output.name, new Date(), Long.toString(a + b)));
}
@@ -73,17 +74,34 @@ public class PlainJavaExample {
public static void main(String[] args) throws Exception {
System.out.println("Starting producer");
+ int chunks = 10;
+ final int chunk = 2000;
+
DataSource ds = createDataSource();
Connection c = ds.getConnection();
SqlEffectExecutor sqlEffectExecutor = new SqlEffectExecutor(ds);
QueueSystem queueSystem = QueueSystem.initialize(sqlEffectExecutor);
- JdbcQueueService queueService = queueSystem.queueService;
+ final JdbcQueueService queueService = queueSystem.queueService;
- Queue queue = queueService.lookupQueue(c, inputName, interval, true);
+ final Queue queue = queueService.lookupQueue(c, inputName, interval, true);
+
+ for (int i = 0; i < chunks; i++) {
+ long start = currentTimeMillis();
+ sqlEffectExecutor.transaction(new SqlEffect.Void() {
+ @Override
+ public void doInConnection(Connection c) throws SQLException {
+ for (int j = 0; j < chunk; j++) {
+ queueService.schedule(c, queue, new Date(), asList("10", "20"));
+ }
+ }
+ });
+ long end = currentTimeMillis();
- queueService.schedule(c, queue, new Date(), asList("10", "20"));
+ long time = end - start;
+ System.out.println("Scheduled " + chunk + " tasks in " + time + "ms, " + (((double) chunk * 1000)) / ((double) time) + " chunks per second");
+ }
c.commit();
}
diff --git a/src/test/resources/logback.xml b/src/test/resources/logback.xml
index 676eac5..a9e4a25 100755
--- a/src/test/resources/logback.xml
+++ b/src/test/resources/logback.xml
@@ -2,16 +2,18 @@
<logger name="io.trygvis" level="DEBUG"/>
<!-- <logger name="org.springframework" level="INFO"/> -->
- <logger name="org.springframework" level="INFO"/>
+ <logger name="org.springframework" level="DEBUG"/>
+<!--
<logger name="org.springframework.jdbc" level="INFO"/>
<logger name="org.springframework.jdbc.datasource.DataSourceTransactionManager" level="DEBUG"/>
<logger name="org.springframework.orm" level="INFO"/>
<logger name="org.springframework.transaction" level="DEBUG"/>
+-->
<logger name="org.hibernate" level="INFO"/>
<logger name="org.hibernate.SQL" level="INFO"/>
- <logger name="com.jolbox" level="TRACE"/>
+ <logger name="com.jolbox" level="INFO"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>