Updated Branches: refs/heads/master 6c3840a15 -> afc7d5d6b
WICKET-4665 Add a new AjaxChannel that discards any Ajax requests if there is a running request in the same channel Add JS unit test for the new AjaxChannel.Type.ACTIVE. Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/afc7d5d6 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/afc7d5d6 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/afc7d5d6 Branch: refs/heads/master Commit: afc7d5d6b7848d3eac1462ca132ad6df324abed2 Parents: 6c3840a Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Mon Jul 23 16:24:28 2012 +0300 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Mon Jul 23 16:24:28 2012 +0300 ---------------------------------------------------------------------- .../java/org/apache/wicket/ajax/AjaxChannel.java | 2 +- wicket-core/src/test/js/channels.js | 83 +++++++++++++-- 2 files changed, 73 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/afc7d5d6/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxChannel.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxChannel.java b/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxChannel.java index d7bead8..7d404c6 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxChannel.java +++ b/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxChannel.java @@ -20,7 +20,7 @@ import org.apache.wicket.util.io.IClusterable; import org.apache.wicket.util.lang.Args; /** - * A Channel that used to process Ajax requests. + * A Channel used to define how Ajax requests are processed at the client side. * * Channels are either: * <ul> http://git-wip-us.apache.org/repos/asf/wicket/blob/afc7d5d6/wicket-core/src/test/js/channels.js ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/js/channels.js b/wicket-core/src/test/js/channels.js index d584221..6dc99c4 100644 --- a/wicket-core/src/test/js/channels.js +++ b/wicket-core/src/test/js/channels.js @@ -19,13 +19,19 @@ jQuery(document).ready(function() { module('Wicket.ChannelManager'); + /** + * Tests queueing channel. + * For 0 to 9 adds callback functions that just appends the current value of + * the counter to the 'result'. + * Verifies that the final result contains all values of the counter. + */ test('queue', function () { var cm = new Wicket.ChannelManager() ch = 'name|s', i = 0, result = ''; - + for (; i < 10; i++) { cm.schedule(ch, function () { result += i; @@ -36,12 +42,24 @@ jQuery(document).ready(function() { equal(result, '0123456789'); }); + /** + * Tests 'drop' channel. + * For 0 to 9 adds callback functions to the queueing channel. Only for the + * value of 5 adds a callback function to the drop channel. + * The execution starts with 0 but the DROP callback (for 5) drops the callbacks for + * 1, 2, 3 and 4, so they are missed. '5' registers a '!drop!' and then all following + * queueing callbacks are executed. + * The final result is "0!drop!10101010" + * - 0 for the first queueing callback + * - !drop! for the 5th + * - a '10' for 6, 7, 8 and 9 (because I didn't find a way to pass the current value of 'i') + */ test('drop', function () { - + expect(1); - + stop(); - + var cm = new Wicket.ChannelManager(), // the manager name = 'name', // the channel's name chq = name + '|s', // the channel(s) to queue @@ -53,22 +71,22 @@ jQuery(document).ready(function() { queueCallback = function(k) { result += k; cm.done(chq); - + if (++j === (number / 2)) { start(); - + //equal(result, '0!drop!6789'); // desired check, but cannot find how to pass // the current value to the channel's callback - + equal(result, '0!drop!10101010'); // one '10' for 6,7,8,9 - } - } + } + }; for (; i < number; i++) { cm.schedule(chq, function () { - // how to pass the current value of 'i' ?! + // TODO: how to pass the current value of 'i' ?! setTimeout(queueCallback, 1, i); }); @@ -76,11 +94,54 @@ jQuery(document).ready(function() { if (i === number / 2) { cm.schedule(chd, function() { result += '!drop!'; - cm.done('name|d'); + cm.done(chd); }); } } }); + /** + * Tests 'active' channel type. + * Schedules one long running request and 10 normal ones after it. + * All 10 normal ones should be discarded. + */ + test('active', function () { + + expect(1); + + stop(); + + var cm = new Wicket.ChannelManager(), // the manager + name = 'name', // the channel's name + cha = name + '|a', // the active channel + number = 10, // the number of requests to schedule while the active request is still running + i = 0, // the current iteration + j = 0, // the counter that decides when to release the test + result = '', // the container for the actual result + queueCallback = function() { + + // run in a timeout to simulate long running request + setTimeout(function() { + start(); + ok(true, "The initial request is executed!"); + + // mark the channel non-busy + cm.done(cha); + }, 100); + } + + // schedule the long running callback (the active one) + cm.schedule(cha, queueCallback); + + // try to schedule more requests + // they will be disacarded because the channel is busy + for (; i < number; i++) { + + cm.schedule(cha, function () { + ok(false, "Requests in the active channel should not be executed.") + }); + } + + }); });
