--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
* createLocked( key ) // returns true if key does not exist (and locks it), false otherwise
* put( key, value ) // verifies lock, stores a value AND removes the lock
* get( key ) // Blocks until key exists and is not locked, then returns the value
.doIf( session => tokenCache.createLocked( key ) ) {
exec( getToken...saveAs( TOKEN ) )
.exec( session => {
tokenCache.put( key, session( TOKEN ).as[String] );
session
})
}
.exec( session => session.set( TOKEN, tokenCache.get( key ) )
createLocked ( key ) {
result = false
synchronize on tokenMap {
if ( ! tokenMap.has( key ) )
tokenMap.add( key, "" )
lockMap.add( key, Thread.ID )
result = true
}
return result
}
put ( key, value ) {
synchronize on tokenMap {
if ( ! tokenMap.has( key ) ||
! lockMap.has( key ) ||
lockMap.get( key ) != Thread.ID )
throw( "You have to createLocked(key) before you can put a value into it!" )
tokenMap.update( key, value )
lockMap.remove( key )
}
}
get ( key ) {
successful = false
value = uninitialized
do {
synchronize on tokenMap {
if ( tokenMap.has( key ) && ! lockMap.has( key ) ) {
value = tokenMap.get( key )
successful = true
}
}
if ( ! successful ) then sleep 100ms
} while ( ! successful )
return value
}
You received this message because you are subscribed to a topic in the Google Groups "Gatling User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gatling/bfpKd_9d6gk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
import scala.collection._
import java.util.concurrent.ConcurrentHashMap
import scala.collection.JavaConverters._
class LookupCache {
val cache : concurrent.Map[String,String] = new ConcurrentHashMap() asScala
val locked : concurrent.Map[String,String] = new ConcurrentHashMap() asScala
// first thread to call lock(key) returns true, all subsequent ones will return false
def lock ( key: String, who: String ) : Boolean = locked.putIfAbsent(key, who ) == None
// only the thread that first called lock(key) can call put, and then only once
def put( key: String, value: String, who: String ) =
if ( locked.get( key ).get == who )
if ( cache.get( key ) == None )
cache.put( key, value )
else
throw new Exception( "You can't put more than one value into the cache! " + key )
else
throw new Exception( "You have not locked '" + key + "'" )
// any thread can call get - will block until a non-null value is stored in the cache
// WARNING: if the thread that is holding the lock never puts a value, this thread will block forever
def get( key: String ) = {
if ( locked.get( key ) == None )
throw new Exception( "Must lock '" + key + "' before you can get() it" )
var result : Option[String] = None
do {
result = cache.get( key )
if ( result == None ) Thread.sleep( 100 )
} while ( result == None )
result.get
}
}
object Login {
. . .
private val tokenCache = new LookupCache()
def process =
doIf( session => tokenCache.lock( session( USER_NAME ).as[String], session.userId ) ) {
// code that does the login and stores the token into TOKEN_VALUE
. . .
// save the token into the cache for next time
.exec( session => {
tokenCache.put(
session( USER_NAME ).as[String],
session( TOKEN_VALUE ).as[String],
session.userId
)
session
})
}
// pull the token out of the cache for use in subsequent tests
.exec( session => session.set( TOKEN_VALUE, tokenCache.get( session( USER_NAME ).as[String] ) ) )
}
. . .
val scn = scenario( MyTest )
.exec( Login.process )
--
Hi..thanks for the post..I have same requirement but the token gets expire for every one hour..I need to pass new token for every hour..could u pls suggest me the solution
--
You received this message because you are subscribed to a topic in the Google Groups "Gatling User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gatling/bfpKd_9d6gk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thank u so much John..
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
setUp(GetAuthToken.authenticate.inject(atOnceUsers(1)).protocols(api_svc),
CreateUser.source.inject(atOnceUsers(1)).protocols(api_svc),
SendMessage.message.inject(atOnceUsers(1)).protocols(ingest_svc))