-
Notifications
You must be signed in to change notification settings - Fork 103
Dynamic Plugin
Vinay Chella edited this page Nov 18, 2016
·
5 revisions
Dynamic Plugin in NDBench is supported for Java
/ Groovy script
. A user can write scripts in Java
/Groovy
to add new workloads without going through compile, build and deployment phases for any quick or short running workloads. Dynamic Plugin is just an implementation of the NdBenchClient
plugin interface.
Below is an example of one such Dynamic Plugin
package com.netflix.ndbench.plugin.sample;
import com.google.common.collect.Maps;
import com.netflix.ndbench.api.plugin.DataGenerator;
import com.netflix.ndbench.api.plugin.NdBenchClient;
import com.netflix.ndbench.api.plugin.annotations.NdBenchClientPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
@NdBenchClientPlugin("DynamicPlugin1")
public class DynamicPlugin1 implements NdBenchClient{
private static final Logger Logger = LoggerFactory.getLogger(DynamicPlugin1.class);
private final Map<String, String> data = Maps.newConcurrentMap();
private DataGenerator dataGenerator;
private static final String ResultOK = "Ok";
private static final String CacheMiss = null;
/**
* Initialize the client
*
* @throws Exception
*/
@Override
public void init(DataGenerator dataGenerator) throws Exception {
this.dataGenerator = dataGenerator;
Logger.info("Initialized DynamicPlugin1");
}
/**
* Perform a single read operation
*
* @param key
* @return
* @throws Exception
*/
@Override
public String readSingle(String key) throws Exception {
String res = data.get(key);
if(res!=null)
{
if(res.isEmpty())
{
throw new Exception("Data retrieved is not ok ");
}
}
else
{
return CacheMiss;
}
return ResultOK;
}
/**
* Perform a single write operation
*
* @param key
* @return
* @throws Exception
*/
@Override
public String writeSingle(String key) throws Exception {
data.put(key, this.dataGenerator.getRandomValue());
return ResultOK;
}
/**
* shutdown the client
*/
@Override
public void shutdown() throws Exception {
Logger.info("Shutting down InMemoryTestPlugin");
}
/**
* Get connection info
*/
@Override
public String getConnectionInfo() throws Exception {
return String.format("DynamicPlugin1 - ConnectionInfo :: Key Count: "+data.size());
}
/**
* Run workflow for functional testing
*
* @throws Exception
*/
@Override
public String runWorkFlow() throws Exception {
return null;
}
}