0

We've got Java and C++ implementations of our product, which is a distributed messaging system.

I'm writing a framework to run a system test across multiple servers. I need our "test coordinator" process to send instructions to each server telling it what to do (e.g. send 100 sample messages, or wait for a message, etc).

I'd really like to implement this by sending a script to each server containing its instructions. This allows me to create dumb test servers, with all the intelligence embedded in the test instructions.

If all my servers were Java I'd write this in Groovy or a similar language. But I'd like our C++ implementation to parse the same script. I'm wondering if I could execute Javascript to call Java/C++ classes to send messages etc.

Is there a neat way of doing this?

If all else fails I'll create an XML format to declaratively contain the test parameters (rather than imperatively containing the test instructions). But this would require the test servers to contain more test-specific intelligence than I'd like.

Any advice gratefully received.

Phil Harvey
  • 1,160
  • 4
  • 13
  • 19
  • doest [this](http://stackoverflow.com/questions/819536/how-to-call-java-function-from-c) help ? – StackFlowed Dec 13 '11 at 09:38
  • I don't know if you are providing too much context or too little? I find myself asking how do your servers look and how invasive do you want the tests to be? But then I also think if you simply want to run a script in C++ and Java all the context is too much – Dirk Dec 13 '11 at 09:43

4 Answers4

2

There are JavaScript parsers for C++ and Java available, so that's definitely something you could use; I don't think that it's a good idea however: the Javascript code can of course interact with your Java code and your C++ code; the problem is, if you want your Javascript code to be ignorant of whether it runs on the C++ or Java basis, it doesn't actually make much sense to call Java/C++ from it, since these calls are again language- (and even engine-)specific.

The simpler solution might be to use a declarative format as you say, but I wouldn't go for XML unless the data needs to be exchanged with a broader audience; instead I'd use e.g. JSON, which is supported very nicely on Java and C++

The best solution (albeit probably also the one involving the highest effort to develop) is probably to develop your own DSL (domain specific language), and parsers for it in both C++ and Java.

Community
  • 1
  • 1
codeling
  • 11,056
  • 4
  • 42
  • 71
  • JSON is fine as a light-weight data interchange format. At this point, however, the op is basically looking for integration of web services. We can advise him to re-implement everything from scratch with JSON processing in C++/Java, but learning WSDL and following its patterns may be more "future-proof" (e.g. if someone adds Scala/Objective-C to the mix, having the service defined and knowing the standard procedure will make extensibility simpler) – Visionary Software Solutions Dec 13 '11 at 09:54
  • Thanks for the response. I wasn't sure how my Javascript could interact with my Java/C++ code. Do you have any idea how I'd specify these "external function calls" in my Javascript? – Phil Harvey Dec 13 '11 at 11:44
  • For calling Java/C++ functions from Javascript, see the links in my answer. Also, I updated it a little: I probably didn't make it clear enough before that I don't really think JavaScript is a good idea for this kind of scenario, since when calling C++ or Java you'd tie your Javascript code to one engine or language (or you'll have to make it overly complicated by adding conditional parts for whether it runs on C++ or Java) – codeling Dec 13 '11 at 12:44
2

Maybe have a look at LUA. It is well supported in C++ and it seems like there is support for Java as well (see this question)

Community
  • 1
  • 1
Dirk
  • 1,184
  • 6
  • 22
1

This is the kind of inter-operability WSDL was originally designed to facilitate. I'm not sure why you'd want to invent an XML format to do what SOAP already does. I mean, you could, but it'd be a maintenance nightmare for the next guy. Plus, introducing another programming language (which is client side, unless you want to add NodeJS into the mix) to act as a glue layer between the two increases the complexity of the system.

What I would do is:

  1. define a high level language agnostic interface
  2. create implementations for the interface in Java and C++

If you're sending commands to the servers, it may be appropriate to look into using the Command pattern to encapsulate the set of known commands (which I assume is enumerated in your requirements). You can use Batch Commands using Composite.

Then your "Test Coordinator" would build a batch command, send it to the server of choice using the declared service, and your implementations could process those commands in language specific ways. Depending on the types of commands your system has, it may be appropriate to have each implementation delegate to Ant or Make.

  • Thanks for the response. I can see how WSDL is useful for sending a single command to a server. However, I'd really like to be able to send a set of simple instructions (including loops and maybe conditionals), which is why I was wondering about sending a chunk of script (eg Javascript). – Phil Harvey Dec 13 '11 at 11:42
  • ...hence why I recommended using the Command pattern. Your WSDL endpoints could accept an instance of the general interface (which could be a BatchCommand Composite containing multiple commands), then your implementations could call the `execute()` method on each of them. Each command's `execute()` could have whatever conditionals, loops, and other related pieces you want. Of course, this is probably a good time to say that a good Messaging system like RabbitMQ(http://www.rabbitmq.com/documentation.html) or OpenMQ(http://mq.java.net/) should make it pretty easy to do this stuff. – Visionary Software Solutions Dec 13 '11 at 16:11
1

You could consider using CORBA too... :)

Owen
  • 4,063
  • 17
  • 58
  • 78