Query Coherence using JMeter - java

This is the situation I'm in:
I have a web service that is using the Coherence grid to store data for faster results. The grid holds specific DTO objects -- When new data comes in from the users, I update these DTOs. Now, I need to write specific JMeter tests for this. I can add a EndPoint (Restful WS) to collect these DTOs to verify that the objects are being updated, but that's kind of mixing the QA and Dev.
Is there a way to connect directly to the Grid using JMeter and query it for my objects? Or even any way to create a stand-alone java app and run it through Jmeter (add specific params for querys) to return the objects..
Thanks guys!
Ninn
EDIT: java class to collect coherence objects
package disclosed.jmeter;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;
public class JmeterTest extends AbstractJavaSamplerClient{
#Override
public Arguments getDefaultParameters() {
// TODO Auto-generated method stub
return null;
}
#Override
public SampleResult runTest(JavaSamplerContext arg0) {
CacheFactory.getCluster().getMemberSet();
NamedCache cache = CacheFactory.getCache("myCache");
System.out.println("The value taken from the cache is: " + cache.get("message"));
SampleResult result = new SampleResult();
result.setResponseCode((String) cache.get("message"));
return result;
}
#Override
public void setupTest(JavaSamplerContext arg0) {
// TODO Auto-generated method stub
}
#Override
public void teardownTest(JavaSamplerContext arg0) {
// TODO Auto-generated method stub
}
}

Yes, you can query any service from JMeter, either if you have Java library to access it, or by simulating raw TCP/UDP network traffic.
Best way is to have existing Java library to access service. Then you may use it from BeanShell Sampler, or write custom Sampler, it's easy.
Further details strongly depends on library you choose.

Related

Geolocalization with Bing and Java

Can I use the Bing Maps API with Java for geolocation? I have the API key but I can't find anything on the net.
I've found a method with an Excel Macro that works but isn't enough, I need a java console script to do it.
Cheers, Damiano.
There doesn't appear to be any official way to make use of the Maps API in Java.
However, there is an unofficial Java wrapper for the API located here. This hasn't been updated in a while, so there's no guarantee it will still work, but it should be a good starting point for implementing geocoding requests.
There is also a method for implementing reverse-geocoding requests in the same wrapper at client.reverseGeocode().
import net.virtualearth.dev.webservices.v1.common.GeocodeResult;
import net.virtualearth.dev.webservices.v1.geocode.GeocodeRequest;
import net.virtualearth.dev.webservices.v1.geocode.GeocodeResponse;
import com.google.code.bing.webservices.client.BingMapsWebServicesClientFactory;
import com.google.code.bing.webservices.client.geocode.BingMapsGeocodeServiceClient;
import com.google.code.bing.webservices.client.geocode.BingMapsGeocodeServiceClient.GeocodeRequestBuilder;
public class BingMapsGeocodeServiceSample {
public static void main(String[] args) throws Exception {
BingMapsWebServicesClientFactory factory = BingMapsWebServicesClientFactory.newInstance();
BingMapsGeocodeServiceClient client = factory.createGeocodeServiceClient();
GeocodeResponse response = client.geocode(createGeocodeRequest(client));
printResponse(response);
}
private static void printResponse(GeocodeResponse response) {
for (GeocodeResult result : response.getResults().getGeocodeResult()) {
System.out.println(result.getDisplayName());
}
}
private static GeocodeRequest createGeocodeRequest(BingMapsGeocodeServiceClient client) {
GeocodeRequestBuilder builder = client.newGeocodeRequestBuilder();
builder.withCredentials("xxxxxx", null);
builder.withQuery("1 Microsoft Way, Redmond, WA");
// builder.withOptionsFilter(Confidence.HIGH);
return builder.getResult();
}
}

Steps to Call a Mule flow from Java class

I am new to Mule and I need to call a flow from Java class. Can anyone give steps please?
you can do it by following below steps
1) In order to make a call, first your flow should have the VM as inbound endpoint.
2) in your java code, get the Mulecontext from MuleEventContext.
3) get the client() from MuleContext then use send method. below is the sample code
MuleContext mContext = eventContext.getMuleContext();
mContext.getClient().send(VM URL, payload);
The VM URL in the send() is the name of the VM Queue path (sometimes you may need to prefix it with 'vm://...' - example: 'vm://myVMQueuePath'.
Any issues let me know.
I have tried this is it did work. I have created java class inside any-point studio and called the java from a main flow. Java is calling the second flow using VMQ. Here is my Java Class. Hope this helps
package mulewithjava;
import org.mule.api.MuleContext;
import org.mule.api.MuleEventContext;
import org.mule.api.MuleMessage;
import org.mule.api.lifecycle.Callable;
public class CallMuleFlow implements Callable {
#Override
public Object onCall(MuleEventContext eventContext) throws Exception {
// TODO Auto-generated method stub
String payload = (String) eventContext.getMessage().getPayload();
MuleContext mContext = eventContext.getMuleContext();
MuleMessage msg= eventContext.getMessage();
mContext.getClient().send("vm://VMQ", msg);
return "After Flow Calling";
}
}

JavaHL.Unable to commit with my java application

I want to control my Subversion environment (Sliksvn 1.8.10) with a small Java programm on a Windows 7 64 bit machine. I need to use JavaHL (1.8.x) not SVNKIt. I have implemented a funktion to checkout a repository, add files to a work copy and commit files to repository. The checkout and the add function works fine so far. The problem ist now, that the commit-funktion don't work correctly.
public void commit()
{
Set<String> paths = new HashSet<String>();
paths.add( "C:\\Users\\XXX\\Documents\\SVNTEST\\Test3" );
Depth dep = Depth.infinity;
);
CommitMessageCallback handler = new CommitMessageCallback()
{
#Override
public String getLogMessage(Set<CommitItem> arg0) {
// TODO Auto-generated method stub
System.out.println(arg0.size());
return null;
}
};
CommitCallback callback = new CommitCallback()
{
#Override
public void commitInfo(CommitInfo arg0) {
// TODO Auto-generated method stub
System.out.println(arg0.getAuthor());
}
};
try
{
client.commit( paths, dep, true, false, null, null, handler, callback );
}
catch( ClientException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
When i process the commit function, then i get from the CommitMessageCallback function the amount of the commit items. This works still. My problem is now, that don't receive any CommitInfo from the CommitCallback function. I think maybe, the process breaks up in der subversion environment and my function get no result. After the process, the commit Items are still in svn status "Item is scheduled for Addition".
I work on this problem since a few days with different version of the JavaHL.jar api, but it was not successful. The big problem is also, that i receive no error message and i dont know what is wrong in code.
Have anybody a idea what is wrong in my commit function ?
Perhaps is the libsvnjavahl-1.dll file not compatible with certain JavaHL Api's ?
Thank you very much
Best regards Simon
Okay, i solved the problem now. The easy solution was to use the org.tigris.subversion instead of the org.apache.subversion library classes. But the question is, why exist two different version from the JavaHL library ?

How to return multiple results through runTest method in Java request sampler for JMeter?

Hi guys I am relatively new to Jmeter and I had a question regarding overriding the runTest method in custom java request sampler. I want to get saparate time durations for all the transactions in my logic but all I can see is just one single duration between result.sampleStart() and result.sampleEnd() methods as the method can return only one single result. Any friends out here have got any suggestions as to how to get separate time durations? Here's my code for custom Java sampler :
package JMeterClient;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
public class JMeterSample extends AbstractJavaSamplerClient {
/* #Override public Arguments getDefaultParameters() {
Arguments defaultParameters = new Arguments();
defaultParameters.addArgument("", "");
defaultParameters.addArgument("", "");
defaultParameters.addArgument("", "");
return defaultParameters; } */
#Override
public SampleResult runTest(JavaSamplerContext arg0) {
SampleResult result = new SampleResult();
boolean success = true;
result.sampleStart();
SampleMethods methods= new SampleMethods();
result.sampleStart();
methods.randomNumberGenerator();
result.sampleEnd();
result.getEndTime();
methods.reverseString();
methods.run();
result.sampleEnd();
result.setSuccessful(success);
return result;
}
}
As far as I understand your question, you trying to build a result tree where you will be having one parent sample and a number of sub-samples. If so, according to How to use BeanShell guide you should look into the following method:
SampleResult.addSubResult()
as per description,
addSubResult
public void addSubResult(SampleResult subResult)
Add a subresult and adjust the parent byte count and end-time.
Parameters: subResult -

Exchange messages on JADEX 2.4

I have to make a work with BDI Agents and for that i will use JADEX 2.4 but i have a big problem. The documentation is a bit poor and i can't exchange messages between agents.
I have read this article http://www.activecomponents.org/bin/view/AC+Tutorial/05+Provided+Services
And i'm trying make the same thing on my code but no success. I need to know how to do 2 things for make my work: send a message from one agent to other, and send a message from one agent to all agents. Anyone knows how to do that?
The code that i have is the following:
ChatSystem.java
package agents;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import ....
#Service
public class ChatSystem implements IChatService{
#ServiceComponent
protected IInternalAccess agent;
protected IClockService clock;
protected DateFormat format;
#ServiceStart
public IFuture<IClockService> startService(){
format = new SimpleDateFormat("hh:mm:ss");
final Future<IClockService> ret = new Future<IClockService>();
IFuture<IClockService> fut = agent.getServiceContainer().getRequiredService("clockservice");
fut.addResultListener(new DelegationResultListener<IClockService>(ret)
{
public void customResultAvailable(IClockService result)
{
clock = result;
super.customResultAvailable(null);
}
});
return ret;
}
#Override
public IFuture<Void> message(String nick, String text,
boolean privatemessage) {
// TODO Auto-generated method stub
//System.out.println(" received at" + text);
System.out.println(agent.getComponentIdentifier().getLocalName()+" received at "
+" from: "+nick+" message: "+text);
return null;
}
}
HelperAgent.java
package agents;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import .....
#Agent
#Service
#RequiredServices({#RequiredService(name="clockservice", type=IClockService.class,binding=#Binding(scope=RequiredServiceInfo.SCOPE_PLATFORM)),#RequiredService(name="chatservices", type=IClockService.class,binding=#Binding(scope=RequiredServiceInfo.SCOPE_PLATFORM,dynamic=true),multiple=true)})
#ProvidedServices(#ProvidedService(type=IChatService.class, implementation=#Implementation(ChatSystem.class)))
public class HelperAgent {
#Agent
protected MicroAgent agent;
#AgentBody
public void AgentBody()
{
IFuture<IClockService> fut = agent.getServiceContainer().getRequiredService("clockservice");
fut.addResultListener(new DefaultResultListener<IClockService>()
{
public void resultAvailable(IClockService cs)
{
System.out.println("Time for a chat, buddy: "+new Date(cs.getTime()));
}
});
IFuture<Collection<IChatService>> chatservices = agent.getServiceContainer().getRequiredServices("chatservices");
chatservices.addResultListener(new DefaultResultListener<Collection<IChatService>>()
{
public void resultAvailable(Collection<IChatService> result)
{
for(Iterator<IChatService> it=result.iterator(); it.hasNext(); )
{
IChatService cs = it.next();
cs.message(agent.getComponentIdentifier().getName(), "test",false);
}
}
});
}
}
Anyone can help me?
Regards
In Jadex you work with active components representing enhanced agents, i.e. in addition to sending and receiving messages you can work with services. Agents can expose services using Java interfaces and other agents can simply fetch these services via their type. Using services communication is done without having to know agent identifities. This helps in building more SOA driven solutions dynamic service providers.
If you want to communicate via messages the API depends on the type of component you are using. In case of micro agents (as shown in your snippets) you can just prepare a FIPA message and call sendMessage on the agent API as shown below:
Map msg = new HashMap();
msg.put(SFipa.CONTENT, content);
msg.put(SFipa.PERFORMATIVE, SFipa.QUERY_IF);
msg.put(SFipa.CONVERSATION_ID, "someuniqueid");
msg.put(SFipa.RECEIVERS, new IComponentIdentifier[]{receiver});
msg.put(SFipa.SENDER, getComponentIdentifier());
agent.sendMessage(msg, SFipa.FIPA_MESSAGE_TYPE);
with 'agent' being the injected MicroAgent.
Kind regards
Lars

Categories