FYI, here is access to the mock queue I inject into the code during
the unit tests. In addition to working around the limitation with the
QueueFactory (because my Queue provider in test mode returns "new
MockQueue();" instead of "QueueFactory.getDefaultQueue();", the mock
provides accessors that allows the tests to verify that the expected
tasks have been inserted into the queue.

http://github.com/DomDerrien/two-tiers-utils/blob/master/src/Java/com/google/appengine/api/labs/taskqueue/MockQueue.java

A+, Dom
--
On Dec 6, 12:12 am, Dom Derrien <dominique.derr...@gmail.com> wrote:
> Max,
>
> I've an issue probably related to my tests that recreate an
> environement at each step (as unit tests usually does ;). The issue is
> related to the re-creation of a Queue with the same name (the default
> one).
>
> Here is the exception with part of the stack trace:
> com.google.appengine.api.labs.taskqueue.TaskAlreadyExistsException:
> Task name already exists :
>     at
> com.google.appengine.api.labs.taskqueue.QueueApiHelper.translateError
> (QueueApiHelper.java:76)
>     at
> com.google.appengine.api.labs.taskqueue.QueueApiHelper.makeSyncCall
> (QueueApiHelper.java:32)
>     at com.google.appengine.api.labs.taskqueue.QueueImpl.add
> (QueueImpl.java:235)
>     at com.google.appengine.api.labs.taskqueue.QueueImpl.add
> (QueueImpl.java:225)
>     at twetailer.task.LocationValidator.process(LocationValidator.java:
> 119)
>
> Here is the code with cause the error:
>     Queue queue = QueueFactory.getDefaultQueue();
>     queue.add(
>             url(ApplicationSettings.get().getServletApiPath() + "/
> maezel/processCommand").
>                 param(Command.KEY, commandKey.toString()).
>                 method(Method.GET)
>     );
>
> I can understand you want to avoid the duplication but this is a
> regression...
>
> Do you have a workaround for this issue too? Something to reset the
> factory...
>
> At the same time, can you tell me how, from the code of the test, if
> we can verify that tasks have been added to the queue as expected? For
> now, I've to rely on yet another mock class ;)
>
> Thanks,
> A+, Dom
> --
> Any way to
>
> On Dec 5, 11:05 pm, Dom Derrien <dominique.derr...@gmail.com> wrote:
>
> > Hi Max,
>
> > To be able cover my code with unit tests, I created a mock class for
> > the App Engine environment (http://github.com/DomDerrien/two-tiers-
> > utils/blob/master/src/Java/com/google/apphosting/api/
> > MockAppEngineEnvironment.java). As reported in my recent blog post
> > (http://domderrien.blogspot.com/2009/11/unit-tests-mock-objects-and-
> > app-engine.html), it's inspired from your documentation and from a
> > post of App Engine fan.
>
> > FYI, it seems to me that the official SDK still requires the
> > workaround. Thanks to your suggestion, the updated mock let the tests
> > passing as before ;)
>
> >     private class MockApiProxyEnvironment implements
> > ApiProxy.Environment {
> >         // ...
> >         public Map<String, Object> getAttributes() {
> >             Map<String, Object> out = new HashMap<String, Object>();
>
> >             // Only necessary for tasks that are added when there is
> > no "live" request
> >             // 
> > See:http://groups.google.com/group/google-appengine-java/msg/8f5872b05214...
> >             out.put("com.google.appengine.server_url_key", "http://
> > localhost:8080");
>
> >             return out;
> >         }
> >     };
>
> > A+, Dom
> > --
> > On Dec 3, 7:01 pm, "Max Ross (Google)" <maxr+appeng...@google.com>
> > wrote:
>
> > > Vince,
>
> > > We added a last minute fix for this in the SDK that just went out.  Could
> > > you please try your code with the official SDK download?
>
> > > Thanks,
> > > Max
>
> > > On Thu, Dec 3, 2009 at 12:15 PM, Max Ross (Google) <
>
> > > maxr+appeng...@google.com <maxr%2bappeng...@google.com>> wrote:
> > > > Sure, sorry for the trouble, and thanks for trying out the prerelease!
>
> > > > Max
>
> > > > On Thu, Dec 3, 2009 at 12:12 PM, Vince Bonfanti 
> > > > <vbonfa...@gmail.com>wrote:
>
> > > >> That fixed it. Thanks.
>
> > > >> Vince
>
> > > >> On Thu, Dec 3, 2009 at 2:24 PM, Max Ross (Google) <
> > > >> maxr+appeng...@google.com <maxr%2bappeng...@google.com>> wrote:
>
> > > >>> Vince,
>
> > > >>> As a workaround, try setting the missing environment attribute 
> > > >>> explicitly
> > > >>> before you add the task to the queue:
>
> > > >>> ApiProxy.getCurrentEnvironment().getAttributes().put("com.google.appengine.server_url_key",
> > > >>> "http://localhost:8080";);
>
> > > >>> This should only be necessary for tasks that are added when there is 
> > > >>> no
> > > >>> "live" request and it should have no impact in prod.
>
> > > >>> Sorry for the trouble,
> > > >>> Max
>
> > > >>> On Thu, Dec 3, 2009 at 10:20 AM, Max Ross (Google) <
> > > >>> maxr+appeng...@google.com <maxr%2bappeng...@google.com>> wrote:
>
> > > >>>> Hi Vince,
>
> > > >>>> That sounds like a bug in our code that was a side effect of the
> > > >>>> automatic task execution that now happens in the dev environment.  
> > > >>>> Let me
> > > >>>> see if I can come up with a workaround for you.
>
> > > >>>> Max
>
> > > >>>> On Thu, Dec 3, 2009 at 10:06 AM, Vince Bonfanti 
> > > >>>> <vbonfa...@gmail.com>wrote:
>
> > > >>>>> I just started testing with the 1.2.8 prerelease, and I'm getting 
> > > >>>>> the
> > > >>>>> following exception from Queue.add() in code that works in 1.2.6:
>
> > > >>>>> java.lang.IllegalStateException: Current enviornment must have the
> > > >>>>> server url available via the com.google.appengine.server_url_key 
> > > >>>>> attribute.
>
> > > >>>>> This only happens when Queue.add() is invoked from the servlet 
> > > >>>>> init()
> > > >>>>> method or from a static initializer; if Queue.add() is invoked from 
> > > >>>>> a
> > > >>>>> "regular" request thread, then it works properly.
>
> > > >>>>> Vince
>
> > > >>>>> On Tue, Nov 24, 2009 at 9:00 PM, Ikai L (Google) 
> > > >>>>> <ika...@google.com>wrote:
>
> > > >>>>>> Hello App Engine Developers,
>
> > > >>>>>> As part of our ongoing efforts to improve release quality and
> > > >>>>>> transparency, we will start prereleasing SDKs for early testing. We
> > > >>>>>> hope this gives developers a chance to participate in our release
> > > >>>>>> process by trying out new changes and sending feedback. As of this
> > > >>>>>> morning, the prerelease SDK for our next release, 1.2.8, is 
> > > >>>>>> available
> > > >>>>>> in the familiar download location (note that the filename ends in
> > > >>>>>> 'prerelease.zip'):
>
> > > >>>>>>http://code.google.com/p/googleappengine/downloads/list
>
> > > >>>>>> If you're interested, please download and give it a try locally 
> > > >>>>>> with
> > > >>>>>> your favorite App Engine code. Please note that, as a prerelease, 
> > > >>>>>> this
> > > >>>>>> SDK is not yet supported and still subject to change. Thus, please
> > > >>>>>> don't take critical dependencies or make substantial changes to
> > > >>>>>> production apps based on this SDK.
>
> > > >>>>>> Importantly, this prerelease is purely for the SDK and is intended 
> > > >>>>>> for
> > > >>>>>> local testing and development in dev_appserver. The server-side of 
> > > >>>>>> App
> > > >>>>>> Engine (our production environment) is not at 1.2.8, so deploying 
> > > >>>>>> with
> > > >>>>>> this SDK is not yet supported. In the future, we might enable a
> > > >>>>>> complete SDK and server test environment for prereleases.
>
> > > >>>>>> A few notes on 1.2.8 in particular - this release is primarily for
> > > >>>>>> servicing and updates in preparation for some exciting feature
> > > >>>>>> launches we have in the pipeline. The current release notes (still
> > > >>>>>> subject to change) are included below; these release notes do 
> > > >>>>>> include
> > > >>>>>> changes which will only be available on the server side Admin 
> > > >>>>>> Console
> > > >>>>>> (non-local) once 1.2.8 is formally released.
>
> > > >>>>>> Please try 1.2.8 for local development and send us your feedback!
>
> > > >>>>>> Thanks,
>
> > > >>>>>> App Engine Team
>
> > > >>>>>> Version 1.2.8
> > > >>>>>> =============
> > > >>>>>>  - Support for JAXB. JAXB is included in JDK 1.6 (and App Engine's
> > > >>>>>> production
> > > >>>>>>    servers). If you're using JDK 1.5 with your local dev_appserver,
> > > >>>>>> you will
> > > >>>>>>    need to include the JAXB libraries with your application to use
> > > >>>>>> it.
> > > >>>>>>      http://code.google.com/p/googleappengine/issues/detail?id=1267
> > > >>>>>>  - Added Quota API (com.google.appengine.api.quota) to match Python
> > > >>>>>> API.
> > > >>>>>>  - Low-level Memcache API now supports grabTail() and 
> > > >>>>>> batchIncrement
> > > >>>>>> ().
> > > >>>>>>  - HTTPResponse object now has getFinalUrl() method for 302
> > > >>>>>> redirects.
> > > >>>>>>      http://code.google.com/p/googleappengine/issues/detail?id=1464
> > > >>>>>>  - Java Dev Appserver now automatically executes tasks.  If you
> > > >>>>>> prefer the old
> > > >>>>>>    behavior where tasks do not automatically execute you can use 
> > > >>>>>> the
> > > >>>>>>      -Dtask_queue.disable_auto_task_execution flag when starting 
> > > >>>>>> the
> > > >>>>>> server.
> > > >>>>>>  - Additional file extensions permitted when sending mail.
> > > >>>>>>      http://code.google.com/p/googleappengine/issues/detail?id=494
> > > >>>>>>  - Fixed issue with Java mail handler not processing multipart
> > > >>>>>> messages
> > > >>>>>>    correctly.
> > > >>>>>>  - Fixed agent code included in appengine-local-runtime.jar results
> > > >>>>>> in
> > > >>>>>>    RuntimeException.
> > > >>>>>>      http://code.google.com/p/googleappengine/issues/detail?id=2280
> > > >>>>>>  - Fixed issue with sort orders defined on properties that allow
> > > >>>>>> multiple
> > > >>>>>>    values.
> > > >>>>>>      http://code.google.com/p/googleappengine/issues/detail?id=2349
> > > >>>>>>  - Fixed problem with dropped query strings after requiring log-in.
> > > >>>>>>      http://code.google.com/p/googleappengine/issues/detail?id=2225
> > > >>>>>>  - Removed limitation preventing multiple parameters with the same
> > > >>>>>> name.
> > > >>>>>>      http://code.google.com/p/googleappengine/issues/detail?id=2090
> > > >>>>>>  - Fixed issue with local datastore incorrectly sorting results of
> > > >>>>>> ancestor queries.
> > > >>>>>>      http://code.google.com/p/googleappengine/issues/detail?id=2177
> > > >>>>>>  - New Index building status page in the Admin Console
> > > >>>>>>  - Task Queue now supports purging queues, and deleting tasks and
> > > >>>>>> queues via
> > > >>>>>>    the Admin Console.
> > > >>>>>>      http://code.google.com/p/googleappengine/issues/detail?id=2159
> > > >>>>>>      http://code.google.com/p/googleappengine/issues/detail?id=1740
> > > >>>>>>  - Over Quota HTTP status code changed
>
> ...
>
> read more »

--

You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.


Reply via email to