@Override public void applyRandomMutations(List<Row> planned) throws Exception { KuduConnection connection = getConnection(); KuduSession session = connection.getSession(); KuduTable table = connection.getTable(config.getString(TABLE_CONFIG_NAME)); List<Operation> operations = extractOperations(planned, table); for (Operation operation : operations) { session.apply(operation); } // Wait until all operations have completed before checking for errors. while (session.hasPendingOperations()) { Thread.sleep(1); } // Fail fast on any error applying mutations if (session.countPendingErrors() > 0) { RowError firstError = session.getPendingErrors().getRowErrors()[0]; String errorMessage = String.format("Kudu output error '%s' during operation '%s' at tablet server '%s'", firstError.getErrorStatus(), firstError.getOperation(), firstError.getTsUUID()); throw new RuntimeException(errorMessage); } }
@Test(timeout = 100000) public void testIgnoreAllDuplicateRows() throws Exception { KuduTable table = client.createTable(tableName, basicSchema, getBasicCreateTableOptions()); KuduSession session = client.newSession(); session.setIgnoreAllDuplicateRows(true); for (int i = 0; i < 10; i++) { session.apply(createInsert(table, i)); } for (SessionConfiguration.FlushMode mode : SessionConfiguration.FlushMode.values()) { session.setFlushMode(mode); for (int i = 0; i < 10; i++) { OperationResponse resp = session.apply(createInsert(table, i)); if (mode == SessionConfiguration.FlushMode.AUTO_FLUSH_SYNC) { assertFalse(resp.hasRowError()); } } if (mode == SessionConfiguration.FlushMode.MANUAL_FLUSH) { List<OperationResponse> responses = session.flush(); for (OperationResponse resp : responses) { assertFalse(resp.hasRowError()); } } else if (mode == SessionConfiguration.FlushMode.AUTO_FLUSH_BACKGROUND) { while (session.hasPendingOperations()) { Thread.sleep(100); } assertEquals(0, session.countPendingErrors()); } } }