java/kudu-client/src/test/java/org/apache/kudu/client/TestMultipleLeaderFailover.java
@Test(timeout = 100000)
  public void testMultipleFailover() throws Exception {
    KuduTable table;
    CreateTableOptions builder = getBasicCreateTableOptions();
    String tableName =
        TestMultipleLeaderFailover.class.getName() + "-" + System.currentTimeMillis();
    createTable(tableName, basicSchema, builder);

    table = openTable(tableName);
    KuduSession session = syncClient.newSession();
    final int ROWS_PER_ITERATION = 3;
    final int NUM_ITERATIONS = 10;
    final int TOTAL_ROWS_TO_INSERT = ROWS_PER_ITERATION + NUM_ITERATIONS * ROWS_PER_ITERATION;

    for (int i = 0; i < ROWS_PER_ITERATION; i++) {
      session.apply(createBasicSchemaInsert(table, i));
    }

    waitUntilRowCount(table, ROWS_PER_ITERATION, DEFAULT_SLEEP);

    int currentRows = ROWS_PER_ITERATION;
    for (int i = 0; i < NUM_ITERATIONS; i++) {
      List<LocatedTablet> tablets = table.getTabletsLocations(DEFAULT_SLEEP);
      assertEquals(1, tablets.size());
      HostAndPort hp = findLeaderTabletServerHostPort(tablets.get(0));
      miniCluster.killTabletServerOnHostPort(hp);

      for (int j = 0; j < ROWS_PER_ITERATION; j++) {
        OperationResponse resp = session.apply(createBasicSchemaInsert(table, currentRows));
        if (resp.hasRowError()) {
          fail("Encountered a row error " + resp.getRowError());
        }
        currentRows++;
      }

      miniCluster.restartDeadTabletServerOnHostPort(hp);
      // Read your writes hasn't been enabled, so we need to use a helper function to poll.
      waitUntilRowCount(table, currentRows, DEFAULT_SLEEP);

    }
    waitUntilRowCount(table, TOTAL_ROWS_TO_INSERT, DEFAULT_SLEEP);
  }
/**
   * This test writes 3 rows. Then in a loop, it kills the leader, then tries to write inner_row
   * rows, and finally restarts the tablet server it killed. Verifying with a read as it goes.
   * Finally it counts to make sure we have total_rows_to_insert of them.
   */
This test writes 3 rows. Then in a loop, it kills the leader, then tries to write inner_row
rows, and finally restarts the tablet server it killed. Verifying with a read as it goes.
Finally it counts to make sure we have total_rows_to_insert of them.
This test writes 3 rows . Then in a loop it kills the leader then tries to write inner_row rows and finally restarts the tablet server it killed . Verifying with a read as it goes . Finally it counts to make sure we have total_rows_to_insert of them .
@Test(timeout = 100000)
  public void testMultipleFailover() throws Exception {
    KuduTable table;
    CreateTableOptions builder = getBasicCreateTableOptions();
    String tableName =
        TestMultipleLeaderFailover.class.getName() + "-" + System.currentTimeMillis();
    createTable(tableName, basicSchema, builder);
    table = openTable(tableName);
    KuduSession session = syncClient.newSession();
    final int ROWS_PER_ITERATION = 3;
    final int NUM_ITERATIONS = 10;
    final int TOTAL_ROWS_TO_INSERT = ROWS_PER_ITERATION + NUM_ITERATIONS * ROWS_PER_ITERATION;
    for (int i = 0; i < ROWS_PER_ITERATION; i++) {
      session.apply(createBasicSchemaInsert(table, i));
    }
    waitUntilRowCount(table, ROWS_PER_ITERATION, DEFAULT_SLEEP);
    int currentRows = ROWS_PER_ITERATION;
    for (int i = 0; i < NUM_ITERATIONS; i++) {
      List<LocatedTablet> tablets = table.getTabletsLocations(DEFAULT_SLEEP);
      assertEquals(1, tablets.size());
      HostAndPort hp = findLeaderTabletServerHostPort(tablets.get(0));
      miniCluster.killTabletServerOnHostPort(hp);
      for (int j = 0; j < ROWS_PER_ITERATION; j++) {
        OperationResponse resp = session.apply(createBasicSchemaInsert(table, currentRows));
        if (resp.hasRowError()) {
          fail("Encountered a row error " + resp.getRowError());
        }
        currentRows++;
      }
      miniCluster.restartDeadTabletServerOnHostPort(hp);
      waitUntilRowCount(table, currentRows, DEFAULT_SLEEP);
    }
    waitUntilRowCount(table, TOTAL_ROWS_TO_INSERT, DEFAULT_SLEEP);
  }
@ Test ( timeout = 100000 ) public void testMultipleFailover ( ) throws Exception { KuduTable table ; CreateTableOptions builder = getBasicCreateTableOptions ( ) ; String tableName = TestMultipleLeaderFailover . class . getName ( ) + "-" + System . currentTimeMillis ( ) ; createTable ( tableName , basicSchema , builder ) ; table = openTable ( tableName ) ; KuduSession session = syncClient . newSession ( ) ; final int ROWS_PER_ITERATION = 3 ; final int NUM_ITERATIONS = 10 ; final int TOTAL_ROWS_TO_INSERT = ROWS_PER_ITERATION + NUM_ITERATIONS * ROWS_PER_ITERATION ; for ( int i = 0 ; i < ROWS_PER_ITERATION ; i ++ ) { session . apply ( createBasicSchemaInsert ( table , i ) ) ; } waitUntilRowCount ( table , ROWS_PER_ITERATION , DEFAULT_SLEEP ) ; int currentRows = ROWS_PER_ITERATION ; for ( int i = 0 ; i < NUM_ITERATIONS ; i ++ ) { List < LocatedTablet > tablets = table . getTabletsLocations ( DEFAULT_SLEEP ) ; assertEquals ( 1 , tablets . size ( ) ) ; HostAndPort hp = findLeaderTabletServerHostPort ( tablets . get ( 0 ) ) ; miniCluster . killTabletServerOnHostPort ( hp ) ; for ( int j = 0 ; j < ROWS_PER_ITERATION ; j ++ ) { OperationResponse resp = session . apply ( createBasicSchemaInsert ( table , currentRows ) ) ; if ( resp . hasRowError ( ) ) { fail ( "Encountered a row error " + resp . getRowError ( ) ) ; } currentRows ++ ; } miniCluster . restartDeadTabletServerOnHostPort ( hp ) ; waitUntilRowCount ( table , currentRows , DEFAULT_SLEEP ) ; } waitUntilRowCount ( table , TOTAL_ROWS_TO_INSERT , DEFAULT_SLEEP ) ; }
This test writes 3 rows.
This test writes 3 rows .
// Read your writes hasn't been enabled, so we need to use a helper function to poll.