From 1c0fc92c719f3856653d0efcc5fe4a1fa30b7bac Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 9 Jun 2013 23:22:39 +0200 Subject: wip --- src/test/java/io/trygvis/test/DbUtil.java | 7 ++++-- .../java/io/trygvis/test/PlainJavaExample.java | 26 ++++++++++++++++++---- src/test/resources/logback.xml | 6 +++-- 3 files changed, 31 insertions(+), 8 deletions(-) (limited to 'src/test') 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 @@ - + + - + -- cgit v1.2.3