@Override
  @Before
  public void setUp() throws Exception {

    super.setUp();
    channelFactory = DataChannelFactoryBuilder.construct(RepTestUtils.readRepNetConfig());
    protocol = new Protocol(GROUP_NAME, new NameIdPair(NODE_NAME, 1), null, channelFactory);
    protocol.updateNodeIds(new HashSet<Integer>(Arrays.asList(new Integer(1))));
  }
  /*
   * Test the API: RepNode.shutdownNetworkBackup/restartNetworkBackup service
   * used to disable the service around a replica syncup operation.
   */
  @Test
  public void testLockout() throws IOException {

    setExceptionListener(repEnvInfo[0]);
    repEnvInfo[0].openEnv();
    RepNode repNode = repEnvInfo[0].getRepNode();
    leaveGroupAllButMaster();

    repNode.shutdownNetworkBackup();
    File backupDir = new File(repEnvInfo[1].getEnvHome().getCanonicalPath() + ".backup");
    backupDir.mkdir();
    assertTrue(backupDir.exists());

    DataChannelFactory channelFactory =
        DataChannelFactoryBuilder.construct(RepTestUtils.readRepNetConfig());
    EnvironmentImpl envImpl = createEnvImpl(backupDir);
    try {
      NetworkBackup backup =
          new NetworkBackup(
              repNode.getSocket(),
              backupDir,
              new NameIdPair("n1", (short) 1),
              true,
              envImpl.getFileManager(),
              channelFactory);
      backup.execute();
      fail("expected exception service should not have been available");
    } catch (ServiceConnectFailedException e) {
      /* Expected. */
    } catch (Exception e) {
      fail("unexpected exception" + e);
    }

    repNode.restartNetworkBackup();
    try {
      NetworkBackup backup =
          new NetworkBackup(
              repNode.getSocket(),
              backupDir,
              new NameIdPair("n1", (short) 1),
              true,
              envImpl.getFileManager(),
              channelFactory);
      backup.execute();
    } catch (Exception e) {
      fail("unexpected exception:" + e);
    }

    envImpl.abnormalClose();
  }
  /**
   * Verify that a NetworkBackup that's in progress is aborted by repNode.shutdownNetworkRestore()
   * and therefore during a rollback operation.
   */
  @Test
  public void testNBAbortOnSyncup()
      throws IOException, DatabaseException, ServiceConnectFailedException,
          LoadThresholdExceededException, InsufficientVLSNRangeException {

    setExceptionListener(repEnvInfo[0]);
    repEnvInfo[0].openEnv();
    final RepNode repNode = repEnvInfo[0].getRepNode();
    leaveGroupAllButMaster();
    File backupDir = new File(repEnvInfo[1].getEnvHome().getCanonicalPath() + ".backup");
    backupDir.mkdir();
    DataChannelFactory channelFactory =
        DataChannelFactoryBuilder.construct(RepTestUtils.readRepNetConfig());
    EnvironmentImpl envImpl = createEnvImpl(backupDir);
    NetworkBackup backup =
        new NetworkBackup(
            repNode.getSocket(),
            backupDir,
            new NameIdPair("n1", (short) 1),
            true,
            envImpl.getFileManager(),
            channelFactory);
    CyclicBarrier testBarrier =
        new CyclicBarrier(
            1,
            new Runnable() {
              public void run() {
                /* The syncup should kill the NB */
                repNode.shutdownNetworkBackup();
              }
            });
    backup.setTestBarrier(testBarrier);
    try {
      backup.execute();
      fail("Expected exception");
    } catch (IOException e) {
      /* Expected exception as in progress service was terminated. */
    }

    envImpl.abnormalClose();
  }