Discussion:
Groovy script(s) to generate fake data
Darryl Pentz
2007-04-27 04:15:12 UTC
Permalink
I want to write a script (or scripts) that can generate randomized data for my application so that my dev environment (and test as well) approximates "real world" data. It will create various users, create x number of domain objects, all using fake "seed" data which I provide to the script, and randomize as needed.

Since I'll be using Lucene, I want to have a good word distribution so that the searches can be more real-world'ish. So my idea there is to use random sections of the "Lorem ipsum" text.

Anyway, the challenge for me right now, given my newness with Grails is how to hook into the underlying Grails infrastructure so that Grails automatically provides my desired datasource (dev or test, depending on what I'm doing), maybe injects some needed objects etc.

So I'm looking for some pointers at existing Groovy scripts to look at for this. Or any ideas people might have on where to draw some inspiration for this. I looked at some of the Grails scripts in the Grails /scripts folder, and they provide a few clues in terms of bootstrapping etc. But any advice, feedback would be appreciated from those of you more familiar with the inner workings of Grails.

Regards,
Darryl


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

---------------------------------------------------------------------
To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email
Jez Nicholson
2007-04-27 08:50:11 UTC
Permalink
Hi Darryl,

We used a tool called dbmonster on a different (non-grails) project.
It populates the db directly with test data consisting of random
numbers and words taken from dictionary files. As it interacts
directly with the database it is only useful to an extent. Allocating
ids in a grails manner would need some configuration too. Not sure how
it would be used with the development bootstrap though, as the db is
hsql.

Personally, I would prefer the testdata to be created through my
objects. This is what we currently do in our
conf/DevelopmentBootStrap.groovy. We've populated the system with
around 100 users then we create 500 new ones by combining their first
and last names in different combinations.

def ran = new Random()

for (i in 1..500) {
def gamer1 = Gamer.get(ran.nextInt(Gamer.count()))
def gamer2 = Gamer.get(ran.nextInt(Gamer.count()))
if (gamer1 && gamer2) {
String name1 = gamer1.firstname
String name2 = gamer2.lastname
def dummyName = name1 + " " + name2
def newGamer = new Gamer(name:dummyName).save()
}
}

We then randomly choose people an allocate games to them, etc.

Perhaps the dictionaries from dbmonster could be used to get seed data
from and do something similar?

The ideal would be a new plug-in that explores your data structure and
populates it in a sensible manner from seed data. It could do this
through a combination of convention (e.g. by recognising standard
names for people such as User/Person/Customer), configuration, and
guessing by using the datatypes.

---------------------------------------------------------------------
To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Loading...