2

I have a application that uses gemfire locator and servers. I would like to write an integration test that could help me start a locator & a server within the JVM and also shut them down when ending the tests. I could not find any single documentation which could help me do this.

I have tried starting a locator and a server when the tests start using LocatorLauncher an ServerLauncher. It starts the locator but throws an exception stating IllegalStateException: A connection to a distributed system already exists in this VM.

I am not very good with gemfire and do not understand what am I missing here, or is it that I am trying in a complete wrong direction.

Mukund Jalan
  • 1,145
  • 20
  • 39

1 Answers1

1

It would be useful to know a bit more about what you're trying to test exactly. We have different levels of testing in the Geode codebase. If you can get away with just a server, I'd suggest using the ServerStarterRule in your JUnits. Here is an example of that: https://github.com/apache/geode/blob/f12055ae3ae4b1f4731c0447af0c4cb9abdd4159/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/commands/AlterRegionCommandIntegrationTest.java

This rule will start up a server as part of the JUnit JVM. This means that you won't be able to use a ClientCache at the same time (you cannot have both a ClientCache and a Cache instance in the same JVM instance).

The next level of test is called DUnit testing. This framework allows you to spin up multiple JVMs and form an actual cluster. The best way to use this is with the ClusterStartupRule together with the GfshCommandRule. An example of this would be: https://github.com/apache/geode/blob/10d89ede6f90f046c15e12e3d16aed259d7044b0/geode-cq/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/ListClientCommandDUnitTest.java

Here, various components are being started up including a client VM. The nice thing about using these rules is that they will handle startup and teardown for you in a consistent and safe manner.

Jens D
  • 4,229
  • 3
  • 16
  • 19