private Insert createInsert(int key) { return createBasicSchemaInsert(table, key); } }
private Insert createInsert(KuduTable table, int key) { return createBasicSchemaInsert(table, key); }
private Insert createInsert(int key) { return createBasicSchemaInsert(table, key); }
/** * Load a table of default schema with the specified number of records, in ascending key order. */ public static void loadDefaultTable(KuduClient client, String tableName, int numRows) throws KuduException { KuduTable table = client.openTable(tableName); KuduSession session = client.newSession(); for (int i = 0; i < numRows; i++) { Insert insert = createBasicSchemaInsert(table, i); session.apply(insert); } session.flush(); session.close(); }
@Override public void run() { try { KuduTable table = localClient.openTable(TABLE_NAME); KuduSession session = localClient.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_SYNC); for (int i = 0; i < 100; i++) { Insert insert = createBasicSchemaInsert(table, id * 100 + i); session.apply(insert); } session.close(); } catch (Exception e) { fail("insert thread should not throw exception: " + e); } } });
@Test(timeout = 10000) public void testInsertManualFlushResponseOrder() throws Exception { CreateTableOptions createOptions = getBasicTableOptionsWithNonCoveredRange(); createOptions.setNumReplicas(1); client.createTable(tableName, basicSchema, createOptions); KuduTable table = client.openTable(tableName); KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH); // Insert a batch of some valid and some invalid. for (int i = 0; i < 10; i++) { assertNull(session.apply(createBasicSchemaInsert(table, 100 + i * 10))); assertNull(session.apply(createBasicSchemaInsert(table, 200 + i * 10))); } List<OperationResponse> results = session.flush(); assertEquals(20, results.size()); for (int i = 0; i < 20; i++) { OperationResponse result = results.get(i); if (i % 2 == 0) { assertTrue(result.hasRowError()); assertTrue(result.getRowError().getErrorStatus().isNotFound()); } else { assertTrue(!result.hasRowError()); } } }
@Test(timeout = 10000) public void testInsertAutoFlushSyncNonCoveredRange() throws Exception { CreateTableOptions createOptions = getBasicTableOptionsWithNonCoveredRange(); createOptions.setNumReplicas(1); client.createTable(tableName, basicSchema, createOptions); KuduTable table = client.openTable(tableName); KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_SYNC); List<Integer> nonCoveredKeys = ImmutableList.of(350, 300, 199, 150, 100, -1, -50); for (int key : nonCoveredKeys) { OperationResponse response = session.apply(createBasicSchemaInsert(table, key)); assertTrue(response.hasRowError()); assertTrue(response.getRowError().getErrorStatus().isNotFound()); } }
session.setTimeoutMillis(30000); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_SYNC); session.apply(createBasicSchemaInsert(nonReplicatedTable, 1)).join(); session.apply(createBasicSchemaInsert(nonReplicatedTable, 2)).join();
assertNull(session.apply(createBasicSchemaInsert(table, key))); session.apply(createBasicSchemaInsert(table, key));
int rowCount = 20; for (int i = 0; i < rowCount; i++) { Insert insert = createBasicSchemaInsert(table, i); session.apply(insert); if (i % 2 == 1) { Insert insert = createBasicSchemaInsert(table, i); session.apply(insert); byteSize += insert.getRowOperationSizeBytes();
/** * 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)); }
/** * This test writes 3 rows, kills the leader, then tries to write another 3 rows. Finally it * counts to make sure we have 6 of them. * * This test won't run if we didn't start the cluster. */ @Test(timeout = 100000) public void testFailover() throws Exception { KuduSession session = harness.getClient().newSession(); for (int i = 0; i < 3; i++) { session.apply(createBasicSchemaInsert(table, i)); } // Make sure the rows are in there before messing things up. AsyncKuduScanner scanner = harness.getAsyncClient().newScannerBuilder(table).build(); assertEquals(3, countRowsInScan(scanner)); harness.killTabletLeader(table); for (int i = 3; i < 6; i++) { OperationResponse resp = session.apply(createBasicSchemaInsert(table, i)); if (resp.hasRowError()) { fail("Encountered a row error " + resp.getRowError()); } } scanner = harness.getAsyncClient().newScannerBuilder(table).build(); assertEquals(6, countRowsInScan(scanner)); } }
client.alterTable(tableName, ato); Insert insert = createBasicSchemaInsert(table, 301); session.apply(insert); assertArrayEquals(getKeyInBytes(400), tablets.get(0).getPartition().getPartitionKeyEnd()); insert = createBasicSchemaInsert(table, 201); session.apply(insert); client.alterTable(tableName, ato); insert = createBasicSchemaInsert(table, 202); OperationResponse response = session.apply(insert); assertTrue(response.hasRowError());
Insert insert = createBasicSchemaInsert(table, i); session.apply(insert);
@Test(timeout = 10000) public void testInsertAutoFlushBackgrounNonCoveredRange() throws Exception { CreateTableOptions createOptions = getBasicTableOptionsWithNonCoveredRange(); createOptions.setNumReplicas(1); client.createTable(tableName, basicSchema, createOptions); KuduTable table = client.openTable(tableName); AsyncKuduSession session = asyncClient.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_BACKGROUND); List<Integer> nonCoveredKeys = ImmutableList.of(350, 300, 199, 150, 100, -1, -50); for (int key : nonCoveredKeys) { OperationResponse result = session.apply(createBasicSchemaInsert(table, key)).join(5000); assertTrue(result.hasRowError()); assertTrue(result.getRowError().getErrorStatus().isNotFound()); } RowErrorsAndOverflowStatus errors = session.getPendingErrors(); assertEquals(nonCoveredKeys.size(), errors.getRowErrors().length); for (RowError error : errors.getRowErrors()) { assertTrue(error.getErrorStatus().isNotFound()); } // Insert a batch of some valid and some invalid. for (int key = 90; key < 110; key++) { session.apply(createBasicSchemaInsert(table, key)); } session.flush(); errors = session.getPendingErrors(); assertEquals(10, errors.getRowErrors().length); for (RowError error : errors.getRowErrors()) { assertTrue(error.getErrorStatus().isNotFound()); } }
/** * Creates a local aclient that we auto-close while buffering one row, then makes sure that after * closing that we can read the row. */ @Test(timeout = 100000) public void testAutoClose() throws Exception { try (KuduClient localClient = new KuduClient.KuduClientBuilder(harness.getMasterAddressesAsString()).build()) { localClient.createTable(TABLE_NAME, basicSchema, getBasicCreateTableOptions()); KuduTable table = localClient.openTable(TABLE_NAME); KuduSession session = localClient.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH); Insert insert = createBasicSchemaInsert(table, 0); session.apply(insert); } KuduTable table = client.openTable(TABLE_NAME); AsyncKuduScanner scanner = new AsyncKuduScanner.AsyncKuduScannerBuilder(asyncClient, table).build(); assertEquals(1, countRowsInScan(scanner)); }
@Test public void testConnectionRefused() throws Exception { CreateTableOptions options = getBasicCreateTableOptions(); KuduTable table = client.createTable( "testConnectionRefused-" + System.currentTimeMillis(), basicSchema, options); // Warm up the caches. assertEquals(0, countRowsInScan(client.newScannerBuilder(table).build())); // Make it impossible to use Kudu. harness.killAllTabletServers(); // Create a scan with a short timeout. KuduScanner scanner = client.newScannerBuilder(table).scanRequestTimeout(1000).build(); // Check it fails. try { while (scanner.hasMoreRows()) { scanner.nextRows(); fail("The scan should timeout"); } } catch (NonRecoverableException ex) { assertTrue(ex.getStatus().isTimedOut()); } // Try the same thing with an insert. KuduSession session = client.newSession(); session.setTimeoutMillis(1000); OperationResponse response = session.apply(createBasicSchemaInsert(table, 1)); assertTrue(response.hasRowError()); assertTrue(response.getRowError().getErrorStatus().isTimedOut()); }
int rowCount = 200; for (int i = 0; i < rowCount; i++) { session.apply(createBasicSchemaInsert(table, i));
@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)); } }
OperationResponse response = lowTimeoutSession.apply(createBasicSchemaInsert(table, 1)); assertTrue(response.hasRowError()); assertTrue(response.getRowError().getErrorStatus().isTimedOut());