aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-06-09 23:22:39 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2013-06-09 23:22:39 +0200
commit1c0fc92c719f3856653d0efcc5fe4a1fa30b7bac (patch)
treeab1ebbfbd21fe1fcc5be75d31c5262f65a931641 /src/test/java
parent33e3be55dc2d815cbd0208bf59d12a7e727f3105 (diff)
downloadquartz-based-queue-1c0fc92c719f3856653d0efcc5fe4a1fa30b7bac.tar.gz
quartz-based-queue-1c0fc92c719f3856653d0efcc5fe4a1fa30b7bac.tar.bz2
quartz-based-queue-1c0fc92c719f3856653d0efcc5fe4a1fa30b7bac.tar.xz
quartz-based-queue-1c0fc92c719f3856653d0efcc5fe4a1fa30b7bac.zip
wip
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/io/trygvis/test/DbUtil.java7
-rw-r--r--src/test/java/io/trygvis/test/PlainJavaExample.java26
2 files changed, 27 insertions, 6 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();
}