Archive for Open source

Selenium and the Permission denied to get property Location.href problem

SeleniumI came across a strange behaviour of Selenium and wanted to share my pain with someone really. But first couple of words of introduction. I use Selenium in my current webapp project which I am working on. The application uses quite a lot of javascript (Dojo framework mostly) which can be tested using D.O.H. framework but the Selenium is giving us the final sanity checks, acts as integration test framework and may be used by product owner in an agile environment to drive acceptance on user stories via automated acceptance tests.

Selenium is an excellent package. I really love it. Just to mention integration with various browsers, Selenium IDE, support for integration with build (Selenese ant task) and really easy way of creating and storing the tests as HTML. It is a framework which cannot be ignored by anyone working on webinterfaces.

There is previously mentioned selenese ant task which helps with integration of the Selenium tests and an ant build. You can grab the jar from the Selenium RC distribution.

However as most of the things around us it is not a perfect software. Anyone had the famous “Permission denied to get property Location.href”? Cross domain scripting issues?
In my case I figure out two reasons for above problem and I wanted to share it:

Problem 1:

Let’s look at the following selenium command:

  • open
  • http://host/some/url

Looks good, doesn’t it? So it might work, but it can as well break on another box with the “Permission denied to get property” and some other scary warnings. The solution in this case was simply to remove the host definition from url leaving just:

  • open
  • /some/url

Problem 2:

One of the pages I was testing had redirection in case of the authorization violation. So esentially after single HTTP request the browser was receiving single response with redirection and then performed another request to the URL defined in the redirection. Selenium couldn’t handle that correctly. But again, it wasn’t deterministic, it could work on one box but fail on another. Timing issues etc. Hate that. Neither of the combinations worked in consistent way: openAndWait, open + pause.

The solution in this case required change in the webapp to remove usage of the redirection (which I believe was an ugly way of dealing with the problem anyway).

Hope it will help someone with similar issues. If you know another tricks or something to avoid when using Selenium please contact me or leave a comment here.

Popularity: 65% [?]

Comments (4)

Ubuntu clearly the winner

Linux distros trends

I used Google Trends to check which Linux distribution is the most popular among Google search users. As you could probably easily guess and what is visible on the diagram Ubuntu is clearly the winner at the moment with the biggest number of search requests. What is interesting is that at the beginning of 2003 there were at least three equally popular distributions: Debian, Suse (now OpenSuse) and Mandrake (now Mandriva) with Red Hat slightly behind. Situation changed since then though. Debian sort of maintains its share. But other distributions became less and less popular with Mandrake loosing the most but partially probably due to changed name. Ubuntu with its excellent online community gains attention with linear search volume increase. I hope it will remain like that and then it is a matter of time when Windows with its ridiculous Vista release will go to hell.

Popularity: 39% [?]

Comments (4)

Hibernate Shards

There are situations when you can’t put all data which you need in a single instance of a relational database. The reasons may differ. Maybe because it is too much of the data itself. Or there is a problem with network latency of a distributed architecture. Scaling? Or one of many other reasons. The answer is: horizontal partitioning. The process of splitting up your data sets that once has been called partitioning, now, it has a new name: sharding. If your data doesn’t fit on one machine you split it up into segments and each segment is called a shard. It is term used initially at Google but now spreading everywhere.

So… There is a new project Hibernate Shards which is a framework that is designed to encapsulate and minimize complexity of accessing multiple databases by adding support for horizontal partitioning on top of Hibernate Core. It was once the 20 percent project at Google but it is open-sourced now and licensed under the LGPL. If you know the Core Hibernate API you know the Shards API as its implementation hasn’t violated the Core API. Basic assumptions and paradigms for using Hibernate are still valid as Configuration, SessionFactory, and Session objects are almost exactly the same. Interfaces from Hibernate Core:

  • org.hibernate.Session
  • org.hibernate.SessionFactory
  • org.hibernate.Criteria
  • org.hibernate.Query

have shard-aware extensions:

  • org.hibernate.shards.session.ShardedSession
  • org.hibernate.shards.ShardedSessionFactory
  • org.hibernate.shards.criteria.ShardedCriteria
  • org.hibernate.shards.query.ShardedQuery

The implementations for these four interfaces serve as a sharding engine that knows how to apply an application-specific sharding logic. This logic is a set of rules how data is distributed across its shards. To specify this logic we have to implement the interfaces below:

  • org.hibernate.shards.strategy.selection.ShardSelectionStrategy
  • org.hibernate.shards.strategy.resolution.ShardResolutionStrategy
  • org.hibernate.shards.strategy.access.ShardAccessStrategy

Hibernate Shards comes with a couple of simple implementations of these interfaces. For instance for the Shard Selection Strategy we have choice of sequential (load balanced round robin) or parallel access.

To finish the topic of the sharding logic I shall mention the id generation as well. As the standard database sequences can’t be used in distributed environment we have a choice of two primary key generators:

  • ShardedUUIDGenerator - that generates a big random number
  • ShardedTableHiLoGenerator - that uses a table in one of the shards to generate the primary key. Obviously it is a single point of failure for our system.

Although project is still in its early stage and even the creators warn about possible glitches this nice wrapper for hiding all the complexity of distributing data around multiple relational databases is very much worth looking at, especially if the Hibernate is already used as the ORM tool of choice.

Popularity: 50% [?]

Comments

Flickrfs - because the Flickr Uploader sux

FlickrI can recall a conversation with psd from early this year about why I think current way of uploading photos to flickr sux big time. I treat flickr as repository and backup of _all_ my photos (12525 photos at the moment, still growing) and not just as a photo blog. It means that very often I have to upload quite a lot of them in batches. The existing solutions just make me angry (how shabby is the standard Flickr Uploadr!) when I have to tag them and correctly name or create sets. I am not (yet) a mac user. Maybe there is something more user friendly, I hope.

So… Coming back to the conversation with psd I have told him that unless there is some clever integration with OS which will make the process of uploading more smooth it will be always the pain. I expected as well a bit more metadata to be populated by camera automatically. How cool would be to have GPS and geo-tag all the photos when taking them. That’s not the end. I would expect as well to be able to define some tags in a camera.

That would solve a bit problem with tags. The other problems are setting permissions, creating sets etc. For pretty long time I couldn’t find any tool which I liked. Lately after migrating all my home computers to Gutsy I found something called Flickrfs as an available package. It is a virtual filesystem which mounts a flickr account as any other data file storage. It synchronizes the flickr account with local filesystem and shows photos as images files with all metadata represented as text files.

Imagine that. You can upload photos to flickr just by using cp command, the same applies to downloading photos (even if Flickr itself makes it as hard as possible to get back of your own photos). Deleting is as easy as invoking rm. You can set permissions using standard chmod command and define sets by creating symlinks with ln.

I like the idea itself very much. The Flickrfs is created and maintained mainly by one person so there might be some small “bugletes” but I still support this project and wish it the best. Well done Manish Rai Jain!

Popularity: 28% [?]

Comments

Eclipse 3.3 leaks permgen space

EclipseSome of you who use Eclipse 3.3 with Sun JVM might notice that it crashes from time to time. Those who have many plugins certainly experienced this more often. Problem and solution for this bug is very trivial but worth mentioning: leaking permgen space. Comes back like November flu! Just to remind the permgen space is a memory for storing “data needed by the virtual machine to describe objects that do not have an equivalence at the Java language level. For example objects describing classes and methods are stored in the permanent generation“. More information about permgen can be found in an article about tuning garbage collection.

To fix the problem edit your eclipse.ini and add following lines:

-XX:PermSize=128M
-XX:MaxPermSize=256M

You might also try Eclipse 3.3.1.1 which includes a fix for the above problem.

Enjoy!

Popularity: 48% [?]

Comments (1)

Integrating AStyle into your Ant build

AntThis blog entry will introduce you how to integrate AStyle into your Ant build.

Short introduction: In my current project I work on software which generates SDKs for multiple languages consuming Web21C services . The SDKs are SOAP webservice clients for multiple languages as Java, Python, PHP or .Net (new are comming soon). XSLT transformations are extensively in use to achieve the goal of generating those SDKs.

The problem is that we are facing a trade off:

  • we have ugly formatted XSL to be able to generate correctly formatted output code
  • we can have pretty formatted and easy to maintain and read XSL but not correctly formatted output in particular language

Let’s assume that we are not crazy yet and we will not follow the first option. The second option looks better but is still not perfect. We need to plug a tool which will do the dirty job for us: correct indentation, format and beautify our output source. Artistic Style (AStyle) has been selected as the tool as it is small, simple, fast tool and supports both Java and C#.

However the AStyle has couple of downsides:

  • doesn’t have easy integration with Ant
  • accepts only list of files for transformation, there is no recursive mode

Let’s assume that all source files to be transformed are in folder generated, with multiple subfolders. As there is no integration with Ant we will have to use <exec/> task. Something like:

<property name="astyle.exe" location="${astyle.home}/astyle.exe"></property>
<exec executable="${astyle.exe}" dir="${basedir}">
    <arg value="--mode=java"></arg>
    <arg value="--style=java"></arg>
    <arg value="--suffix=none"></arg>
    <arg value="${sourcefile}"></arg>
</exec>

AStyle accepts following arguments:

astyle [options] SourceFile1.java SourceFile2.java SourceFile3.java [...]

Wouldn’t it be nice to have -R option?

Our first approach could be construction of a space separated list of paths to all files in folder generated and then using this as argument in exec task. We would quickly realize that we have a possible problem with maximum length of a command line executed via exec task which is just 256 characters. Better will be to execute astyle many times, for each file to be formatted. Core Ant task are not enough in this case. We have to use ant-contrib tasks. First copy ant-contrib jar to your ANT_HOME/lib and add in your build:

<taskdef resource="net/sf/antcontrib/antlib.xml" />

It will let you use <for/> task which should help us to solve our problem as it will allow us to iterate over list of paths and execute external command for each one. The final ant task could look like:

<target name="format">
    <for param="file">
        <path>
  	    <fileset dir="${generated}" includes="**/*.java"/>
  	</path>
  	<sequential>
  	    <property name="astyle.exe" location="${astyle.home}/astyle.exe" />
	    <exec executable="${astyle.exe}" dir="${basedir}">
	        <arg value="--mode=java"/>
	        <arg value="--style=java"/>
	        <arg value="--suffix=none"/>
	        <arg value="@{file}"/>
	    </exec>
  	</sequential>
    </for>
</target>

Fist we define a name of the parameter to pass the tokens or files to the sequential, let’s call it just file. Note that for makes use of ant’s macrodef task, so the @{} notation is used for parameter substitution. Next we define path including all java files in generated folder. The last step is to use <sequential/> block where the execution of astyle.exe will happen for each source file defined using @{file} parameter.

Popularity: 41% [?]

Comments

Mylyn web connector

Again about the Mylyn plugin. If you install Eclipse 3.3 Europa there isn’t, due to the Mylar -> Mylyn renaming, the web connector plugin which could be found in the Mylyn 1.0. This plugin is useful when we are working with an unsupported web based bug repository. The plugin still exists but can be found in a separate update site. Simply add new remote update site: http://download.eclipse.org/tools/mylyn/update/extras to find a set of Mylyn plugins including the web connector.

If I find some time I will try to connect to Scrum Works repository using that plugin. If someone has done it already please let me know.

Popularity: 39% [?]

Comments

Mylyn and Implementors

I migrated last week to Eclipse 3.3.0 and during usual routine of installing plugins (must to have: JBossIDE, SpringIDE, Subclipse) I decided to try two plugins I haven’t been using yet. First is a subproject from Eclipse Tools project called Implementors. It fills a gap in standard Eclipse source code navigation which doesn’t really well support working with interfaces. With Implementors plugin it is possible to jump to implementation of an interface and to an interface of implementation. Sounds unimpressive yeah? But it is really useful plugin and I could call it a “Plugin of the Month in Category Simple but Cool”. If I had that category. So, whenever you edit a class which has dependencies defined as interfaces just hit Alt-F3 on a method from an interface to go to implementation. If you have more than one implementation you will have a choice. Ctrl-Alt-F3 will take you to interface. Thanks Andy for introducing that plugin!

The second plugin I wanted to write about is Mylyn formerly known as Mylar. I have heard about this plugin long time ago, talked about it with Tomaz many times but never actually tried it out. My bad and now I regret that. Because I found Mylyn just awesome. In couple of words Mylyn is a task focused ui for Eclipse which filters all unneeded information noise, leaving you only relevant information. It monitors your activity when working on a particular task and creates a context of that task which makes it is very easy to switch between tasks. No more navigating, searching, scrolling again. Mylyn integrates with repositories like JIRA, Bugzilla or Trac. There is also option of using local task repository.

As I use Scrum Works for task management I would like to use that repository with Mylyn but couldn’t find a connector for that one. Anyone solved that problem?

Popularity: 37% [?]

Comments

Close
E-mail It