@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); } }
@Before public void setUp() throws Exception { CreateTableOptions builder = new CreateTableOptions(); builder.addHashPartitions( Lists.newArrayList(schema.getColumnByIndex(0).getName()), TABLET_COUNT); table = harness.getClient().createTable(TABLE_NAME, schema, builder); KuduSession session = harness.getClient().newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_BACKGROUND); // Getting meaty rows. char[] chars = new char[1024]; for (int i = 0; i < ROW_COUNT; i++) { Insert insert = table.newInsert(); PartialRow row = insert.getRow(); row.addInt(0, random.nextInt()); row.addInt(1, i); row.addInt(2, i); row.addString(3, new String(chars)); row.addBoolean(4, true); session.apply(insert); } session.flush(); assertEquals(0, session.countPendingErrors()); }
/** * Test collecting errors from multiple tablets. * @throws Exception */ @Test(timeout = 100000) public void multiTabletTest() throws Exception { String tableName = TestRowErrors.class.getName() + "-" + System.currentTimeMillis(); createFourTabletsTableWithNineRows(harness.getAsyncClient(), tableName, DEFAULT_SLEEP); table = harness.getClient().openTable(tableName); KuduSession session = harness.getClient().newSession(); session.setFlushMode(KuduSession.FlushMode.AUTO_FLUSH_BACKGROUND); int dupRows = 3; session.apply(createInsert(12)); session.apply(createInsert(22)); session.apply(createInsert(32)); session.flush(); RowErrorsAndOverflowStatus reos = session.getPendingErrors(); assertEquals(dupRows, reos.getRowErrors().length); assertEquals(0, session.countPendingErrors()); }
@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()); } } }
/** * Tests scanning a table with non-covering range partitions. */ @Test(timeout = 100000) public void testScanNonCoveredTable() throws Exception { client.createTable(TABLE_NAME, basicSchema, getBasicTableOptionsWithNonCoveredRange()); KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_BACKGROUND); KuduTable table = client.openTable(TABLE_NAME); for (int key = 0; key < 100; key++) { session.apply(createBasicSchemaInsert(table, key)); } for (int key = 200; key < 300; key++) { session.apply(createBasicSchemaInsert(table, key)); } session.flush(); assertEquals(0, session.countPendingErrors()); assertEquals(200, countRowsForTestScanNonCoveredTable(table, null, null)); assertEquals(100, countRowsForTestScanNonCoveredTable(table, null, 200)); assertEquals(0, countRowsForTestScanNonCoveredTable(table, null, -1)); assertEquals(0, countRowsForTestScanNonCoveredTable(table, 120, 180)); assertEquals(0, countRowsForTestScanNonCoveredTable(table, 300, null)); }
@Test public void testBasicWorkflow() throws Exception { KuduTable table = client.createTable(TABLE_NAME, basicSchema, getBasicCreateTableOptions()); dropConnectionsAndExpireToken(); KuduSession session = client.newSession(); session.setTimeoutMillis(OP_TIMEOUT_MS); session.apply(createBasicSchemaInsert(table, 1)); session.flush(); RowErrorsAndOverflowStatus errors = session.getPendingErrors(); assertFalse(errors.isOverflowed()); assertEquals(0, session.countPendingErrors()); dropConnectionsAndExpireToken(); KuduTable scanTable = client.openTable(TABLE_NAME); AsyncKuduScanner scanner = new AsyncKuduScanner.AsyncKuduScannerBuilder(asyncClient, scanTable) .scanRequestTimeout(OP_TIMEOUT_MS) .build(); assertEquals(1, countRowsInScan(scanner)); dropConnectionsAndExpireToken(); client.deleteTable(TABLE_NAME); assertFalse(client.tableExists(TABLE_NAME)); } }