Max, With your settings added to my MockAppEngineEnvironment.tearDown() method, there's no more issue.
Personally, I think using my MockQueue which stores the submitted TaskOptions instances is easier to use. I can access each attributes individually (URL, method, parameters, etc.) with the TaskOptions getters. When dealing with TaskStateInfo instances, I need to extract the submitted parameters from the URL or from the body (depending on the method being GET or POST/PUT). A bit cumbersome to me ;) Thanks for your help, A+, Dom -- On Dec 7, 1:36 pm, "Max Ross (Google)" <[email protected]> wrote: > Hi Dom, > > We definitely should have updated our unit-testing documentation to include > more information for testing with queues. I'll make sure this gets > addressed. In the meantime, I believe this should do what you want: > > QueueFactory.getDefaultQueue().add(TaskOptions.Builder.taskName("task29")); > ApiProxyLocalImpl proxy = new ApiProxyLocalImpl(new File(".")){}; > LocalTaskQueue ltq = (LocalTaskQueue) > proxy.getService(LocalTaskQueue.PACKAGE); > ltq.flushQueue(QueueFactory.getDefaultQueue().getQueueName()); > > QueueFactory.getDefaultQueue().add(TaskOptions.Builder.taskName("task29")); > > You can use LocalTaskQueue.getQueueStateInfo() to inspect and assert on the > state of your queues: > > LocalTaskQueue ltq = (LocalTaskQueue) > proxy.getService(LocalTaskQueue.PACKAGE); > for (QueueStateInfo qsi : ltq.getQueueStateInfo().values()) { > for (QueueStateInfo.TaskStateInfo ti : qsi.getTaskInfo()) { > System.out.println(ti.getTaskName()); > } > } > > Hope this helps, > Max > > On Sat, Dec 5, 2009 at 9:12 PM, Dom Derrien > <[email protected]>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 <[email protected]> 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)" > > > <[email protected]<maxr%[email protected]> > > > > 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) < > > > > > [email protected] <maxr%[email protected]> < > > maxr%[email protected] <maxr%[email protected]>>> 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 <[email protected] > > >wrote: > > > > > >> That fixed it. Thanks. > > > > > >> Vince > > > > > >> On Thu, Dec 3, 2009 at 2:24 PM, Max Ross (Google) < > > > > >> [email protected] <maxr%[email protected]> < > > maxr%[email protected] <maxr%[email protected]>>> 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) < > > > > >>> [email protected] <maxr%[email protected]> < > > maxr%[email protected] <maxr%[email protected]>>> 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 < > > [email protected]>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) < > > [email protected]>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 > > ... > > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
