Posts Tagged Google

Google Iphone Calendar Selector

I got an IPad a while back, and something was always bothering me with it.
It had this really nice looking calendar application that was useless because it only showed one of my 5 google calendars.

Turns out Google tought of that. You need to navigate to their Google Iphone Calendar Selector and select which calendars you want to display in your IPad.

Suddenly my IPad’s calendar app got a lot better. Now if I could only find some way to get a better mail application as well :)

,

No Comments

Talk on Python Testing on Google AppEngine

Last night I held a talk at GTUG Stockholm about testing on Google AppEngine. Here are the slides that I used during the presentation.

, ,

No Comments

Specifying tests

The latest post on the Google Testing blog is quite interesting. Philip Zembrod discusses the readability of code developed by TDD and found that sometimes reading the test first didn’t always help to understand the written code.

He makes a valid point. I started objecting to using mocks when it was pointed out to me that most of the tests produced with mocks weren’t readable. They typically don’t follow AAA (Arrange Act Assert), and thus work poorly as specifications. But it’s not the mocks, it’s how understandable the test is as a specification. Is it easy to understand what the test does?

If I look at a test 5 months from now, and it is unclear what its testing and how its testing it. Then the ROI of developing that test is lower than it could be.

,

No Comments

Testing on Google AppEngine (Python SDK)

Testing in Python and Django is pretty straight forward. However I wanted to write tests that assert email sending, URL fetching and other external sources. Making sure the intended code is executed and allowing me to write fuller tests.

These external actions are accessed through Google’s API, and there are some posts about how to test on Google AppEngine.

Here is an example by AppEngine Fan where he uses Mocker to mock out the external API calls. An approach that shows the power of the mocking library, but to my taste it results in too much code, and too much details about the mocking framework in the test making it harder to read. This ties back to a previous post I wrote about testing without Mocks.

What I wanted was some way to keep my original code intact and still have a pretty self explanatory test.

After some more research I found out that all API calls in the Python SDK are done through a proxy map. Allowing you to replace the behavior of AppEngine with your own, stubbed behavior. This method is used in this example (that still uses the mocking framework), and also this post on the user group was that location where I first noticed it.

This made me dig through the source code available in the SDK about how exactly this stub map worked. What I noticed was that if you started using the stub map, you needed to setup all the stubs.

As far as I could tell there was not means to replace just a single stub and let the map remain otherwise intact. Which was a bit of a trouble for me. One of the reasons I researched it was because I didn’t want to have tons of setup code in my tests.

Since my test code is important I thought I’d show how I want my tests to look like.

Requirements for good test-code:

  • Easy to read (Arrange-Act-Assert,Minimal setup code in the test)
  • Fast execution
  • non-fragile (black box testing the most external interface accessible for testing)

I want specific events in JS-Analytics to send an email to the administrators of JS-Analytics. The use case is covered with testing, but I wanted to add a test for this new requirement.

Here is what the test looks like:

    def test_given_a_new_project_an_email_is_sent_informing_the_admins(self):
      request = HttpRequest()
      request.user = User(username="…", user=users.User("…"))
      request.method = "POST"
      request.POST = {"title":"test"}
      index(request)
      self.assertEqual("project created", self.getMessages()[0].subject())
      

As you can see I wish to use the Log pattern for test sent messages. This allows me to check the sent messages in order. There is a method that allows me to access a copy of all sent emails, with their complete structure. Allowing me to assert different aspects of the emails.

To support this I created a base-class that adds the behavior I want as setup code. This setup code is generic and only specific for AppEngine aspects of the code. Here is the structure:

image The base-class called ServiceTest sets up the stub map. I added two stubs that change the behavior from the normal stubs. These add support for setting content that will be accessed through the URLFetch service, and the logging of email messages.

Since no call ever cross the service boundary to actually do anything, the execution time isn’t compromised.

Here is an example of the setContent usage:

    def test_fetching_arrangement_example(self):
      self.setResponse("http://url-to-be-fetched", "fake-content")
      request = HttpRequest()
      result = view_that_does_fetching(request)
      self.assertEqual(result.content, "fake-content")

As you can see its pretty straight forward to Arrange the which content should be returned where.

This structure should be so generic that anyone could use it, so I added a copy of my base-class free to use by others.

, ,

No Comments

Presenting JS-Analytics

With the success we had with EQATEC Analytics at RemoteX I started looking around for something similar, but for JavaScript. I didn’t find anything that satisfied my needs.

Thus I created my own error collecting and analysis tool, and named it JS-Analytics.

You use it similar to how you use Google Analytics, you add a few given script tags to your website and JS-Analytics will try to collect any unhandled JavaScript error that occurs, and send information about it back to JS-Analytics website.

JS-Analytics uses a combination of window events to collect errors. These events aren’t available on all browsers so JS-Analytics will use JQuery to provide cross browser support. This means that cross browser support is only available for JQuery code.

For more information about how it works I recommend this page.

Right now this JS-Analytics provides just some basic analysis. But I felt that it was better to announce it and hopefully get some feedback on it, than to carry on without any feedback.

, , , , , , ,

No Comments

Interesting issue on GAE issue list

I was browsing around the issue lists on Google AppEngine, just some midnight light reading before going to bed…

I stumbled on the following issue, marked as critical:

http://code.google.com/p/googleappengine/issues/detail?id=1970

What’s interesting about it is that this is also what is causing all the problems with running Grails development on Windows machines. If this is fixed, then building Grails for GAE on Windows machines might work without any workarounds. Lets hope the Critical focus remains on this issue, and that it is resolved.

, , ,

No Comments

Programming for Android

So I’ve done my first programming for Android phones and thought I’d write a blog post about the experience.

Programming for Android is a bit different from working with the Compact Framework. The abstraction level for the Dalvik applications is somehow high than the Compact Framework application. One difference for example is that there is no main() method to start your application from.

Central for an Android application is its Android Manifest file. This file describes all services and activities available in the application. This is an XML file that helps describe your application to Android, what it’s capabilities are. Each Activity can then be used as an Entry point, but the manifest also describes Services, Content Providers and Broadcast receivers.

What this gives you is a set of loosely coupled components that interact with each other using Intents, that are passed on a system wide message bus. This allows applications interact not only with central parts of the phone, but also with other applications. Which is quite interesting.

Developing in this manner gives you a set of conventions to follow. I feel that they have managed to find a set of conventions that gives direction in the design of the application, but doesn’t confine you.

The SDK also gives you a set of base classes (template method pattern style base classes) that helps you develop common tasks in a standardized way. An example of these are the Task classes that provide threading and scheduling support. I quickly fell in love the the AsyncTask for example.

Android protects the foreground UI thread quite extensively, making these constructs for doing background work important. For example your not allowed to construct or access any UI elements on background threads. This can be handled by using a special Looper construct that effectively divides your Thread code into different parts. One setup part that’s allowed to access, or setup UI components. And one Loop part that does the actual work.

I worked mainly in the Emulator. The emulator feels fast at first, it takes a while to boot up but is quite responsive once booted. That is until you start typing using the computers keyboard. When you do this the emulator feels slow. Apart from a few issues with the emulator loosing “internet connectivity” when my computer Hibernated.

Now it’s time to mention a tool that’s quite helpful when working with Android applications. It’s the adb.exe logcat tool available in the Android SDK. This tool allows you to watch the result of log statements in runtime, and shows stack traces for those errors the occur but you’ve partially managed to take care of (ignored).

This being said there are some things I’m missing when comparing to working with the Compact Framework. For example, working with XML is much easier in the Compact Framework. I hate having to write my own parsing and serialization code, and there are more tools to help me generate code for doing this in the .Net framework.

Also using the HttpClient in the Android SDK is unnecessarily hard. Https works only with some special glue code. And as far as I can tell everyone seems to simply accept any certificate instead of providing support for showing a UI where the user can accept an unknown (self-signed) certificate.

This is all I can think of right now (this is the second time of writing since I had a crash when I tried to post it…). If there are any questions, please ask them. Hopefully they’ll help generate more knowledge about Android development.

, , ,

No Comments

AppEngine + Grails + Cron

I just added a Cron job to “ping” my application every 1 minute. After a short discussion with Paul Cusch, whom commented on one of my previous posts regarding the load request issues Grails on AppEngine is seeing. I decided to give it a try. This solution is entirely based on Paul’s idea I’m just writing it up.

Grails AppEngine plugin is missing a feature to use cron out of the box. I hope to submit a patch for it. This is how it works. You need to have a cron.xml file next to your appengine-web.xml file. In the cron file you describe which url and how often a GET operation should be done on the specified url.

Details can be found here.

I simply added a request to a specified url, which I added to my URL mapping:

"/today"(controller: "user", action = "ping")

Then added a cron file to ping it every minute:

<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
    <cron>
        <url>/today</url>
        <description>Keep the app alive by ping every 1 minutes</description>
        <schedule>every 1 minutes</schedule>
    </cron>
</cronentries>

The cron.xml file I keep in my grails-app/conf directory, following the conventions used by the AppEngine plugin, for similar files.

The user controller unfortunately got the honor for hosting the ping request.

def ping = {
  render "ping ${new Date().toString()}"
}

And there it is. Next time that application is uploaded to the AppEngine, the ping method on the user controller will be executed every 1 minute. Helping to keep the application loaded.

This method comes with a few drawbacks however. The application will still hit loading requests every now and then, and those requests will take from your quota. This setup can easily eat up all your free quota.

Also, if everyone sets up this cron job. Then a lot of quota is wasted in general, which might affect the service for other applications. This workaround tries to fix a problem that should be fixed in the inner workings of AppEngine it self (not excluding changes to Grails initialization).

There is however a query that is ongoing. Google is considering the possibility to allow people to pay for keeping their application in memory. If you would consider such an option then star the this issue. I myself starred it, I think it’s quite acceptable.

I turned the cron loading task off in my application, instead seeing it as an experiment with Cron on Google AppEngine. The payoff for this solution wasn’t that great and for me it comes with the expense of some of my code quality.

, ,

8 Comments

Added precompilation-enabled to AppEngine plugin

In the 1.2.8 version of the AppEngine SDK there is an option to precompile your solution as you deploy it to the AppEngine. Apparently precompilation can save up to 30% runtime on loading requests.

I added the option to turn on the precompilation-enabled setting in appengine-web.xml to the AppEngine plug-in this morning. Hopefully I can submit a patch with change, I’ll get back to that in a bit.

As I’m writing this I’m deploying to AppEngine for the first time. What happens is that during the deployment to Google AppEngine, the appcfg.cmd compiles the solution locally.

Showing the following lines in the input:

37% Cloned 600 files.
40% Uploading 4 files.
52% Uploaded 1 files.
61% Uploaded 2 files.
68% Uploaded 3 files.
73% Uploaded 4 files.
77% Precompiling.
80% Precompiling. 174 files left.
82% Precompiling. 94 files left.
84% Precompiling. 22 files left.
90% Deploying new version.

Now it’s deployed, I’m going to let it run for a while while I fix something else.

I have Pingdom set up for checking the AppEngine project every minute. That way I can see the changes in response time, and from the dashboard I can see if the CPU use goes down.

As far as I can tell, the precompilation doesn’t help with the timeout issues when starting a grails application hosted on AppEngine, it might help, but it doesn’t affect the loading time noticeably. However I for one am going to have my application precompiled.

, ,

No Comments

AppEngine SDK 1.3.0 Release

This SDK release makes Morten (that would be me) a happy camper. Now I have something to do when I get home from work! :)

Release information

http://googleappengine.blogspot.com/2009/12/app-engine-sdk-130-released-including.html

Why am I looking forward to this? It’s the first time I see a mention of performance updates for dynamic languages in AppEngine. I’m upgrading later to night to see what my actual performance boost is.

The blob service is also a welcomed scenario. We’re using something similar in our REST-API in RemoteX Applications.

,

No Comments