public void doTestReconnectOnForcedDisconnect(final boolean createInAppToo) throws Exception {

    IgnoredException.addIgnoredException("killing member's ds");

    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);

    final int locPort = locatorPort;
    final int secondLocPort = AvailablePortHelper.getRandomAvailableTCPPort();

    Invoke
        .invokeInEveryVM(() -> DistributedTestUtils.deleteLocatorStateFile(locPort, secondLocPort));

    final String xmlFileLoc = (new File(".")).getAbsolutePath();

    SerializableCallableIF<DistributedMember> create1 = () -> {
      locatorPort = locPort;
      Properties props = getDistributedSystemProperties();
      props.put(CACHE_XML_FILE, xmlFileLoc + fileSeparator + "MyDisconnect-cache.xml");
      props.put(MAX_WAIT_TIME_RECONNECT, "1000");
      cache = (InternalCache) new CacheFactory(props).create();
      Region myRegion = cache.getRegion("root" + SEPARATOR + "myRegion");
      ReconnectDUnitTest.savedSystem = cache.getDistributedSystem();
      myRegion.put("MyKey1", "MyValue1");
      return savedSystem.getDistributedMember();
    };

    SerializableCallableIF<DistributedMember> create2 = () -> {
      locatorPort = locPort;
      final Properties props = getDistributedSystemProperties();
      props.put(CACHE_XML_FILE, xmlFileLoc + fileSeparator + "MyDisconnect-cache.xml");
      props.put(MAX_WAIT_TIME_RECONNECT, "5000");
      props.put(START_LOCATOR, "localhost[" + secondLocPort + "]");
      props.put(LOCATORS, props.get(LOCATORS) + ",localhost[" + secondLocPort + "]");
      getSystem(props);
      cache = getCache();
      ReconnectDUnitTest.savedSystem = cache.getDistributedSystem();
      Region myRegion = cache.getRegion("root" + SEPARATOR + "myRegion");
      myRegion.put("Mykey2", "MyValue2");
      assertNotNull(myRegion.get("MyKey1"));
      if (createInAppToo) {
        Thread recreateCacheThread = new Thread("ReconnectDUnitTest.createInAppThread") {
          @Override
          public void run() {
            while (!cache.isClosed()) {
              Wait.pause(100);
            }
            try {
              cache = (InternalCache) new CacheFactory(props).create();
              System.err.println(
                  "testReconnectCollidesWithApplication failed - application thread was able to create a cache");
            } catch (IllegalStateException cacheExists) {
              // expected
            }
          }
        };
        recreateCacheThread.setDaemon(true);
        recreateCacheThread.start();
      }
      return cache.getDistributedSystem().getDistributedMember();
    };

    vm0.invoke("Create Cache and Regions from cache.xml", create1);
    final InternalDistributedMember dm =
        (InternalDistributedMember) vm1.invoke("Create Cache and Regions from cache.xml", create2);

    IgnoredException.addIgnoredException("ForcedDisconnectException");
    forceDisconnect(vm1);

    DistributedMember newdm = vm1.invoke("wait for reconnect(1)", () -> {
      final DistributedSystem ds = savedSystem;
      savedSystem = null;
      GeodeAwaitility.await().untilAsserted(new WaitCriterion() {
        @Override
        public boolean done() {
          return ds.isReconnecting();
        }

        @Override
        public String description() {
          return "waiting for ds to begin reconnecting";
        }
      });
      System.out.println("entering reconnect wait for " + ds);
      System.out.println("ds.isReconnecting() = " + ds.isReconnecting());
      boolean failure = true;
      try {
        ds.waitUntilReconnected(getTimeout().toMillis(), MILLISECONDS);
        savedSystem = ds.getReconnectedSystem();
        locator = getLocator();
        assertTrue("Expected system to be restarted", ds.getReconnectedSystem() != null);
        assertTrue("Expected system to be running", ds.getReconnectedSystem().isConnected());
        assertTrue("Expected there to be a locator", locator != null);
        assertTrue("Expected locator to be restarted",
            !((InternalLocator) locator).isStopped());
        failure = false;
        cache = ((InternalLocator) locator).getCache();
        system = cache.getInternalDistributedSystem();
        return ds.getReconnectedSystem().getDistributedMember();
      } catch (InterruptedException e) {
        System.err.println("interrupted while waiting for reconnect");
        return null;
      } finally {
        if (failure) {
          ds.disconnect();
        }
      }
    });
    assertNotSame(dm, newdm);
    // force another reconnect and show that stopReconnecting works
    forceDisconnect(vm1);
    boolean stopped = vm1.invoke("wait for reconnect and stop", () -> {
      final DistributedSystem ds = savedSystem;
      savedSystem = null;
      GeodeAwaitility.await().untilAsserted(new WaitCriterion() {
        @Override
        public boolean done() {
          return ds.isReconnecting() || ds.getReconnectedSystem() != null;
        }

        @Override
        public String description() {
          return "waiting for reconnect to commence in " + ds;
        }

      });
      ds.stopReconnecting();
      assertFalse(ds.isReconnecting());
      DistributedSystem newDs = ds.getReconnectedSystem();
      if (newDs != null) {
        System.err.println("expected distributed system to be disconnected: " + newDs);
        newDs.disconnect();
        return false;
      }
      return true;
    });
    assertTrue("expected DistributedSystem to disconnect", stopped);

    // recreate the system in vm1 without a locator and crash it
    DistributedMember evenNewerdm = (DistributedMember) vm1.invoke(create1);
    forceDisconnect(vm1);
    newdm = waitForReconnect(vm1);
    assertNotSame("expected a reconnect to occur in member", evenNewerdm, newdm);
    Invoke
        .invokeInEveryVM(() -> DistributedTestUtils.deleteLocatorStateFile(locPort, secondLocPort));
  }
bug #51335 - customer is also trying to recreate the cache
geode-core/src/distributedTest/java/org/apache/geode/cache30/ReconnectDUnitTest.java