Databases Reference
In-Depth Information
public void navigate ( user , product ) {
String nav =
"{\"user\": \"${user}\", \"product\": \"${product}\", \"type\": \"PRODUCT
\"}" . toString ()
println "Pushing navigation: ${nav}"
jedis . lpush ( ' navigation ' , nav )
}
...
}
Provide a method called getProductCategoryStats in the AbstractAnalyticsTest
that reads a specific relation from the Redis server. Different tests will also need
to assert against the statistics results in order to check if the topology is behaving as
expected.
public abstract class AbstractAnalyticsTest extends Assert {
...
public int getProductCategoryStats ( String product , String categ ) {
String count = jedis . hget ( "prodcnt:${product}" , categ )
if ( count == null || "nil" . equals ( count ))
return 0
return Integer . valueOf ( count )
}
...
}
A Test Example
In the next snippet, you'll emulate a few product navigations of user “1”, then check
the results. Note that you wait two seconds before asserting to be sure that the results
have been stored to Redis. (Remember that the ProductCategoriesCounterBolt has an
in-memory copy of the counters and sends them to Redis in the background.)
package functional
class StatsTest extends AbstractAnalyticsTest {
@Test
public void testNoDuplication (){
navigate ( "1" , "0" ) // Players
navigate ( "1" , "1" ) // Players
navigate ( "1" , "2" ) // Players
navigate ( "1" , "3" ) // Cameras
Thread . sleep ( 2000 ) // Give two seconds for the system to process the data.
assertEquals 1 , getProductCategoryStats ( "0" , "Cameras" )
assertEquals 1 , getProductCategoryStats ( "1" , "Cameras" )
assertEquals 1 , getProductCategoryStats ( "2" , "Cameras" )
assertEquals 2 , getProductCategoryStats ( "0" , "Players" )
assertEquals 3 , getProductCategoryStats ( "3" , "Players" )
}
}
 
Search WWH ::




Custom Search