diff options
Diffstat (limited to 'src/test/java/io/trygvis/test/PlainJavaExample.java')
-rw-r--r-- | src/test/java/io/trygvis/test/PlainJavaExample.java | 26 |
1 files changed, 22 insertions, 4 deletions
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(); } |