public void handleRepClientEvent() { TestUtils.DEBUGOUT(1, "Got a REP_CLIENT message"); }
public void handleRepNewMasterEvent() { TestUtils.DEBUGOUT(1, "Got a REP_NEW_MASTER message"); TestUtils.DEBUGOUT(1, "My priority: " + priorities[threadNumber]); }
public void run() { String homedirName = baseDirName + threadNumber; TestUtils.removeDir(homedirName); try { homedir = new File(homedirName); homedir.mkdir(); } catch (Exception e) { TestUtils.DEBUGOUT( 2, "Warning: initialization had a problem creating a clean directory.\n" + e); } try { homedir = new File(homedirName); } catch (NullPointerException npe) { // can't really happen :) } TestUtils.DEBUGOUT(1, "Creating worker: " + threadNumber); envConfig = new EnvironmentConfig(); envConfig.setErrorStream(TestUtils.getErrorStream()); envConfig.setErrorPrefix("RepmgrElectionTest test(" + threadNumber + ")"); envConfig.setAllowCreate(true); envConfig.setRunRecovery(true); envConfig.setThreaded(true); envConfig.setInitializeLocking(true); envConfig.setInitializeLogging(true); envConfig.setInitializeCache(true); envConfig.setTransactional(true); envConfig.setTxnNoSync(true); envConfig.setInitializeReplication(true); envConfig.setVerboseReplication(false); ReplicationManagerSiteConfig localConfig = new ReplicationManagerSiteConfig(address, basePort + threadNumber); localConfig.setLocalSite(true); envConfig.addReplicationManagerSite(localConfig); envConfig.setReplicationPriority(priorities[threadNumber]); envConfig.setEventHandler(this); envConfig.setReplicationManagerAckPolicy(ReplicationManagerAckPolicy.ALL); if (masterThreadIndex >= 0) { // If we already have the master, then set it as the bootstrap helper, // otherwise, set local site as new master. ReplicationManagerSiteConfig remoteConfig = new ReplicationManagerSiteConfig(address, basePort + masterThreadIndex); remoteConfig.setBootstrapHelper(true); envConfig.addReplicationManagerSite(remoteConfig); } try { dbenv = new Environment(homedir, envConfig); } catch (FileNotFoundException e) { fail("Unexpected FNFE in standard environment creation." + e); } catch (DatabaseException dbe) { fail("Unexpected database exception came from environment create." + dbe); } try { // If we do not have master, then set local site as new master. if (masterThreadIndex == -1) dbenv.replicationManagerStart(NUM_WORKER_THREADS, ReplicationManagerStartPolicy.REP_MASTER); else dbenv.replicationManagerStart(NUM_WORKER_THREADS, ReplicationManagerStartPolicy.REP_CLIENT); } catch (DatabaseException dbe) { fail("Unexpected database exception came from replicationManagerStart." + dbe); } TestUtils.DEBUGOUT(1, "Started replication site: " + threadNumber); lastSiteStarted = true; try { java.lang.Thread.sleep(1000 * (1 + threadNumber)); } catch (InterruptedException ie) { } if (masterThreadIndex != -1) { // Wait for "Start-up done" for each client, then add next client. ReplicationStats rs = null; int i = 0; do { try { java.lang.Thread.sleep(2000); } catch (InterruptedException e) { } try { rs = dbenv.getReplicationStats(StatsConfig.DEFAULT); } catch (DatabaseException dbe) { dbe.printStackTrace(); fail("Unexpected database exception came from getReplicationStats." + dbe); } } while (!rs.getStartupComplete() && i++ < maxLoopWait); assertTrue(rs.getStartupComplete()); } }