@Override
  protected void createConfigs() throws Exception {
    nodeManager = new InVMNodeManager(false);
    TransportConfiguration liveConnector = getConnectorTransportConfiguration(true);
    TransportConfiguration backupConnector = getConnectorTransportConfiguration(false);

    backupConfig =
        super.createDefaultInVMConfig()
            .clearAcceptorConfigurations()
            .addAcceptorConfiguration(getAcceptorTransportConfiguration(false))
            .setHAPolicyConfiguration(
                new SharedStoreSlavePolicyConfiguration().setAllowFailBack(false))
            .addConnectorConfiguration(liveConnector.getName(), liveConnector)
            .addConnectorConfiguration(backupConnector.getName(), backupConnector)
            .addClusterConfiguration(
                basicClusterConnectionConfig(backupConnector.getName(), liveConnector.getName()));

    backupServer = createTestableServer(backupConfig);

    liveConfig =
        super.createDefaultInVMConfig()
            .clearAcceptorConfigurations()
            .addAcceptorConfiguration(getAcceptorTransportConfiguration(true))
            .setHAPolicyConfiguration(new SharedStoreMasterPolicyConfiguration())
            .addConnectorConfiguration(liveConnector.getName(), liveConnector)
            .addConnectorConfiguration(backupConnector.getName(), backupConnector)
            .addClusterConfiguration(
                basicClusterConnectionConfig(liveConnector.getName(), backupConnector.getName()));

    liveServer = createTestableServer(liveConfig);
  }
  @Test
  public void testToStringObfuscatesPasswords() {
    HashMap<String, Object> params = new HashMap<>();
    params.put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, "secret_password");
    params.put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, "secret_password");

    TransportConfiguration configuration = new TransportConfiguration("SomeClass", params, null);

    Assert.assertThat(configuration.toString(), not(containsString("secret_password")));
  }
 /**
  * There's a case on ClusterConnections that we need to find an equivalent Connector and we can't
  * use a Netty Cluster Connection on an InVM ClusterConnection (inVM used on tests) for that
  * reason I need to test if the two instances of the TransportConfiguration are equivalent while a
  * test a connector against an acceptor
  *
  * @param otherConfig
  * @return {@code true} if the factory class names are equivalents
  */
 public boolean isEquivalent(TransportConfiguration otherConfig) {
   if (this.getFactoryClassName().equals(otherConfig.getFactoryClassName())) {
     return true;
   } else if (this.getFactoryClassName().contains("Netty")
       && otherConfig.getFactoryClassName().contains("Netty")) {
     return true;
   } else if (this.getFactoryClassName().contains("InVM")
       && otherConfig.getFactoryClassName().contains("InVM")) {
     return true;
   } else {
     return false;
   }
 }
 protected final void adaptLiveConfigForReplicatedFailBack(TestableServer server) {
   Configuration configuration = server.getServer().getConfiguration();
   final TransportConfiguration backupConnector = getConnectorTransportConfiguration(false);
   if (server.getServer().getHAPolicy().isSharedStore()) {
     ClusterConnectionConfiguration cc = configuration.getClusterConfigurations().get(0);
     Assert.assertNotNull("cluster connection configuration", cc);
     Assert.assertNotNull("static connectors", cc.getStaticConnectors());
     cc.getStaticConnectors().add(backupConnector.getName());
     // backupConnector is only necessary for fail-back tests
     configuration.getConnectorConfigurations().put(backupConnector.getName(), backupConnector);
     return;
   }
   ReplicatedPolicy haPolicy = (ReplicatedPolicy) server.getServer().getHAPolicy();
   haPolicy.setCheckForLiveServer(true);
 }
 private void startServerChannels() {
   String[] hosts = TransportConfiguration.splitHosts(host);
   for (String h : hosts) {
     SocketAddress address;
     if (useInvm) {
       address = new LocalAddress(h);
     } else {
       address = new InetSocketAddress(h, port);
     }
     Channel serverChannel = bootstrap.bind(address).syncUninterruptibly().channel();
     serverChannelGroup.add(serverChannel);
   }
 }
  private void startServer() throws Exception {
    liveTC = new TransportConfiguration(INVM_CONNECTOR_FACTORY);
    Map<String, TransportConfiguration> connectors = new HashMap<>();
    connectors.put(liveTC.getName(), liveTC);
    List<String> connectorNames = new ArrayList<>();
    connectorNames.add(liveTC.getName());

    Configuration liveConf =
        createBasicConfig()
            .addAcceptorConfiguration(new TransportConfiguration(INVM_ACCEPTOR_FACTORY))
            .setConnectorConfigurations(connectors)
            .setHAPolicyConfiguration(new SharedStoreMasterPolicyConfiguration());

    final long broadcastPeriod = 250;

    final String bcGroupName = "bc1";

    final int localBindPort = 5432;

    BroadcastGroupConfiguration bcConfig1 =
        new BroadcastGroupConfiguration()
            .setName(bcGroupName)
            .setBroadcastPeriod(broadcastPeriod)
            .setConnectorInfos(connectorNames)
            .setEndpointFactory(
                new UDPBroadcastEndpointFactory()
                    .setGroupAddress(groupAddress)
                    .setGroupPort(groupPort)
                    .setLocalBindPort(localBindPort));

    List<BroadcastGroupConfiguration> bcConfigs1 = new ArrayList<>();
    bcConfigs1.add(bcConfig1);
    liveConf.setBroadcastGroupConfigurations(bcConfigs1);

    liveService = addServer(ActiveMQServers.newActiveMQServer(liveConf, false));
    liveService.start();
  }
    public void create() throws Exception {
      Map<String, Object> params0 = new HashMap<>();
      params0.put(TransportConstants.SERVER_ID_PROP_NAME, id);
      liveConnector = new TransportConfiguration(INVM_CONNECTOR_FACTORY, params0, "in-vm-live");

      Map<String, Object> params = new HashMap<>();
      params.put(TransportConstants.SERVER_ID_PROP_NAME, id + ID_OFFSET);
      backupConnector = new TransportConfiguration(INVM_CONNECTOR_FACTORY, params, "in-vm-backup");

      // live
      Configuration conf0 =
          createBasicConfig()
              .setJournalDirectory(getJournalDir(id, false))
              .setBindingsDirectory(getBindingsDir(id, false))
              .addAcceptorConfiguration(new TransportConfiguration(INVM_ACCEPTOR_FACTORY, params0))
              .addConnectorConfiguration(liveConnector.getName(), liveConnector)
              .setHAPolicyConfiguration(new ReplicatedPolicyConfiguration())
              .addClusterConfiguration(basicClusterConnectionConfig(liveConnector.getName()));

      ActiveMQServer server0 = addServer(ActiveMQServers.newActiveMQServer(conf0, true));

      liveContext = new InVMContext();
      liveNode = new JMSServerManagerImpl(server0);
      liveNode.setRegistry(new JndiBindingRegistry(liveContext));

      // backup
      Configuration config =
          createBasicConfig()
              .setJournalDirectory(getJournalDir(id, true))
              .setBindingsDirectory(getBindingsDir(id, true))
              .addAcceptorConfiguration(new TransportConfiguration(INVM_ACCEPTOR_FACTORY, params))
              .addConnectorConfiguration(backupConnector.getName(), backupConnector)
              .addConnectorConfiguration(liveConnector.getName(), liveConnector)
              .setHAPolicyConfiguration(new ReplicaPolicyConfiguration())
              .addClusterConfiguration(
                  basicClusterConnectionConfig(backupConnector.getName(), liveConnector.getName()));

      ActiveMQServer backup = addServer(ActiveMQServers.newActiveMQServer(config, true));

      Context context = new InVMContext();

      backupNode = new JMSServerManagerImpl(backup);
      backupNode.setRegistry(new JndiBindingRegistry(context));
    }
  @Test
  public void testEquals() {
    TransportConfiguration configuration =
        new TransportConfiguration("SomeClass", new HashMap<String, Object>(), null);
    TransportConfiguration configuration2 =
        new TransportConfiguration("SomeClass", new HashMap<String, Object>(), null);

    Assert.assertEquals(configuration, configuration2);
    Assert.assertEquals(configuration.hashCode(), configuration2.hashCode());

    HashMap<String, Object> configMap1 = new HashMap<>();
    configMap1.put("host", "localhost");
    HashMap<String, Object> configMap2 = new HashMap<>();
    configMap2.put("host", "localhost");

    System.out.println("Equals::" + configMap1.equals(configMap2));
    configuration = new TransportConfiguration("SomeClass", configMap1, null);
    configuration2 = new TransportConfiguration("SomeClass", configMap2, null);
    Assert.assertEquals(configuration, configuration2);
    Assert.assertEquals(configuration.hashCode(), configuration2.hashCode());

    System.out.println("Equals::" + configMap1.equals(configMap2));
    configuration = new TransportConfiguration("SomeClass", configMap1, "name1");
    configuration2 = new TransportConfiguration("SomeClass", configMap2, "name2");
    Assert.assertNotEquals(configuration, configuration2);
    Assert.assertNotEquals(configuration.hashCode(), configuration2.hashCode());
    Assert.assertTrue(configuration.isEquivalent(configuration2));

    configMap1 = new HashMap<>();
    configMap1.put("host", "localhost");
    configMap2 = new HashMap<>();
    configMap2.put("host", "localhost3");
    configuration = new TransportConfiguration("SomeClass", configMap1, null);
    configuration2 = new TransportConfiguration("SomeClass", configMap2, null);
    Assert.assertNotEquals(configuration, configuration2);
    Assert.assertNotEquals(configuration.hashCode(), configuration2.hashCode());
  }