/** * Adds a table operation to insert the specified entity to the batch operation. * * @param entity * The {@link TableEntity} to insert. */ public void insert(final TableEntity entity) { insert(entity, false); }
/** * Adds a table operation to insert the specified entity to the batch operation. * * @param entity * The {@link TableEntity} to insert. */ public void insert(final TableEntity entity) { insert(entity, false); }
private Class1 addInsertBatch(TableBatchOperation batch) { Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); batch.insert(ref); return ref; }
private Class1 addInsertBatch(TableBatchOperation batch, boolean echoContent) { Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); batch.insert(ref, echoContent); return ref; }
@Test public void testBatchLockToPartitionKey() { try { TableBatchOperation batch = new TableBatchOperation(); batch.insert(TableTestHelper.generateRandomEntity("jxscl_odata")); batch.insert(TableTestHelper.generateRandomEntity("jxscl_odata2")); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), SR.OPS_IN_BATCH_MUST_HAVE_SAME_PARTITION_KEY); } }
customer.setEmail("Jeff@contoso.com"); customer.setPhoneNumber("425-555-0104"); batchOperation.insert(customer); customer2.setEmail("Ben@contoso.com"); customer2.setPhoneNumber("425-555-0102"); batchOperation.insert(customer2); customer3.setEmail("Denise@contoso.com"); customer3.setPhoneNumber("425-555-0103"); batchOperation.insert(customer3);
@BeforeClass public static void tableQueryTestMethodSetUp() throws Exception { table = TableTestHelper.getRandomTableReference(); table.createIfNotExists(); // Insert 500 entities in Batches to query for (int i = 0; i < 5; i++) { TableBatchOperation batch = new TableBatchOperation(); for (int j = 0; j < 100; j++) { Class1 ent = TableTestHelper.generateRandomEntity("javatables_batch_" + Integer.toString(i)); ent.setRowKey(String.format("%06d", j)); batch.insert(ent); } table.execute(batch); } }
@Test public void testBatchRetrieveAndOneMoreOperationShouldThrow() { Class1 ref2 = TableTestHelper.generateRandomEntity("jxscl_odata"); try { TableBatchOperation batch = new TableBatchOperation(); batch.insert(TableTestHelper.generateRandomEntity("jxscl_odata")); batch.retrieve(ref2.getPartitionKey(), ref2.getRowKey(), ref2.getClass()); fail(); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), SR.RETRIEVE_MUST_BE_ONLY_OPERATION_IN_BATCH); } try { TableBatchOperation batch = new TableBatchOperation(); batch.retrieve(ref2.getPartitionKey(), ref2.getRowKey(), ref2.getClass()); batch.insert(TableTestHelper.generateRandomEntity("jxscl_odata")); fail(); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), SR.RETRIEVE_MUST_BE_ONLY_OPERATION_IN_BATCH); } }
@Test public void testBatchOver100Entities() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); TableBatchOperation batch = new TableBatchOperation(); try { for (int m = 0; m < 101; m++) { batch.insert(TableTestHelper.generateRandomEntity("jxscl_odata")); } this.table.execute(batch, options, null); fail("Batch with over 100 entities should fail."); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Bad Request"); String errorAfterSemiColon = ex.getExtendedErrorInformation().getErrorMessage(); errorAfterSemiColon = errorAfterSemiColon.substring(errorAfterSemiColon.indexOf(":") + 1); assertTrue(errorAfterSemiColon.startsWith("The batch request operation exceeds the maximum 100 changes per change set.")); assertEquals(ex.getErrorCode(), StorageErrorCodeStrings.INVALID_INPUT); } }
@Test @Category(SecondaryTests.class) public void testBatchRemoveRange() throws StorageException { ArrayList<TableOperation> ops = allOpsList(); TableBatchOperation batch = new TableBatchOperation(); batch.addAll(ops); batch.removeRange(0, ops.size()); assertEquals(0, batch.size()); // should be able to add an entity with a different partition key Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata_2"); batch.insert(baseEntity); batch.removeRange(0, 1); batch.addAll(ops); batch.removeRange(0, ops.size() - 1); // should be not be able to add an entity with a different partition key baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata_2"); try { batch.insert(baseEntity); fail(SR.OPS_IN_BATCH_MUST_HAVE_SAME_PARTITION_KEY); } catch (IllegalArgumentException e) { assertEquals(SR.OPS_IN_BATCH_MUST_HAVE_SAME_PARTITION_KEY, e.getMessage()); } batch.removeRange(0, 1); // should be able to add a retrieve to the batch Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); TableOperation queryOp = TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), ref.getClass()); batch.add(queryOp); }
@Test public void testBatchSizeOver4mb() { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); TableBatchOperation batch = new TableBatchOperation(); byte[] datArr = new byte[1024 * 128]; Random rand = new Random(); rand.nextBytes(datArr); // Each entity is approx 128kb, meaning ~32 entities will result in a request over 4mb. try { for (int m = 0; m < 32; m++) { Class1 ref = new Class1(); ref.setA("foo_A"); ref.setB("foo_B"); ref.setC("foo_C"); ref.setD(datArr); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); batch.insert(ref); } this.table.execute(batch, options, null); fail(); } catch (StorageException ex) { assertEquals(ex.getHttpStatusCode(), HttpURLConnection.HTTP_ENTITY_TOO_LARGE); assertEquals(ex.getErrorCode(), StorageErrorCodeStrings.REQUEST_BODY_TOO_LARGE); assertTrue(ex.getMessage().startsWith( "The request body is too large and exceeds the maximum permissible limit.")); } }
@Test public void testBatchRemoveAll() throws StorageException { ArrayList<TableOperation> ops = allOpsList(); TableBatchOperation batch = new TableBatchOperation(); batch.addAll(ops); assertTrue(batch.removeAll(ops)); assertEquals(0, batch.size()); // should be able to add an entity with a different partition key Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata_2"); batch.insert(baseEntity); }
Class1 ent = TableTestHelper.generateRandomEntity("javatables_batch_" + Integer.toString(i)); ent.setRowKey(String.format("%06d", j)); batch.insert(ent);
@Test public void testBatchInsertFail() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); // insert entity Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(ref), options, null); try { TableBatchOperation batch = new TableBatchOperation(); batch.insert(ref); this.table.execute(batch, options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Conflict"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The specified entity already exists")); assertEquals(ex.getErrorCode(), StorageErrorCodeStrings.ENTITY_ALREADY_EXISTS); } }
Class1 ent = TableTestHelper.generateRandomEntity("javatables_batch_" + Integer.toString(i)); ent.setRowKey(String.format("%06d", j)); batch.insert(ent);
Class1 ent = TableTestHelper.generateRandomEntity("javatables_batch_" + Integer.toString(i)); ent.setRowKey(String.format("%06d", j)); batch.insert(ent); Class1 ent = TableTestHelper.generateRandomEntity("javatables_batch_" + Integer.toString(0)); ent.setRowKey(String.format("%06d", j)); batchFromSAS.insert(ent);
batch.insert(ent); if (j == 50) { middleRef = ent;
batch.insert(ref); this.table.execute(batch, options, null);