Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Below is a simple Example of using this rule with default properties:

Code Block
languagejava

@Category(DistributedTest.class)
public class ExampleTest {

  @Rule
  public LocatorServerStartupRule lsRule = new LocatorServerStartupRule(); //See Note 1

  @Test
  public void simpleUsage() throws Exception {
    // start up a default locator in vm0
    MemberVM locator = lsRule.startLocatorVM(0); //See Note 2

    // start up a default server in vm1, joining the locator
    MemberVM server = lsRule.startServerVM(1, locator.getPort()); // see Note 3

    // you can use these attributes of the locator/server
    locator.getName(); // by default this would locator-0
    locator.getPort(); // these are the random ports by default.
    locator.getJmxPort();
    locator.getHttpPort();
    locator.getWorkingDir(); // this should be dunit/vm0 unless the rule is constructed using temp folder.

    // you can also do code invocation inside the vms
    locator.invoke(()->{
      // access the locator started in this VM
      InternalLocator internalLocator = LocatorServerStartupRule.locatorStarter.getLocator();
      // operations and assertions here
    });

    server.invoke(()->{
      // access the cache and server in this VM
      InternalCache cache = LocatorServerStartupRule.serverStarter.getCache();
      CacheServer cacheServer = LocatorServerStartupRule.serverStarter.getServer();
      // operations and assertions here.
    });
  }
}

...

Code Block
languagejava
@Category(IntegrationTest.class)
public class ExampleTest {
  @Rule
  public ServerStarterRule serverRule = new ServerStarterRule().withJMXManager().withRegion(RegionShortcut.REPLICATE, "testRegion");

  @Rule
  public GfshShellConnectionRule gfshRule = new GfshShellConnectionRule();
  
  @Before
  public void before() throws Exception {
    gfshRule.connectAndVerify(serverRule.getJmxPort(), GfshShellConnectionRule.PortType.jmxManger);
  }

  @Test
  public void simpleUsage() throws Exception {
    // gfshRule already connect, ready to execute some command
    String result = gfshRule.execute("list members");
	// examine the result and do some assertions
  }
}

...