public boolean insert(TableType entity) { try { return tableRefrence(entity.getAzureTableName()) .execute(TableOperation.insert(entity)) .getHttpStatusCode() == Response.Status.NO_CONTENT.getStatusCode(); } catch (StorageException e) { LOG.warn("Error performing operation on Storage service", e); } throw new IllegalStateException("Error adding data in table " + entity.getAzureTableName()); }
public boolean update(TableType entity) { try { return tableRefrence(entity.getAzureTableName()) .execute(TableOperation.replace(entity)) .getHttpStatusCode() == Response.Status.NO_CONTENT.getStatusCode(); } catch (StorageException e) { LOG.warn("Error updating row in table: {}", entity.getAzureTableName(), e); } throw new IllegalStateException("Error updating data in table: " + entity.getAzureTableName()); }
public boolean remove(TableType entity) { try { return tableRefrence(entity.getAzureTableName()) .execute(TableOperation.delete(entity)) .getHttpStatusCode() == Response.Status.NO_CONTENT.getStatusCode(); } catch (StorageException e) { LOG.warn("Error updating row in table: {}", entity.getAzureTableName(), e); } throw new IllegalStateException("Error updating data in table: " + entity.getAzureTableName()); } }
public boolean insertOrReplace(TableType entity) { try { final TableResult tableResult = tableRefrence(entity.getAzureTableName()) .execute(TableOperation.insertOrReplace(entity)); switch (Response.Status.fromStatusCode(tableResult.getHttpStatusCode())) { case CREATED: case NO_CONTENT: return true; default: return false; } } catch (StorageException e) { LOG.warn("Error performing operation on Storage service", e); } throw new IllegalStateException("Error insertOrReplace in table " + entity.getAzureTableName()); }
private void testBatchInsert(TableRequestOptions options) throws StorageException { TableBatchOperation batch = new TableBatchOperation(); // Add 3 inserts addInsertBatch(batch); // default echo content (true) addInsertBatch(batch, true); // set echo content to true addInsertBatch(batch, false); // set echo content to false // insert entity Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(ref), options, null); batch.delete(ref); ArrayList<TableResult> results = this.table.execute(batch, options, null); assertEquals(results.size(), 4); Iterator<TableResult> iter = results.iterator(); TableResult res = iter.next(); assertEquals(res.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); res = iter.next(); assertEquals(res.getHttpStatusCode(), HttpURLConnection.HTTP_CREATED); res = iter.next(); assertEquals(res.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // delete assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); }
private void testBatchMerge(TableRequestOptions options) throws StorageException { TableBatchOperation batch = new TableBatchOperation(); addInsertBatch(batch); // insert entity to delete Class1 delRef = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(delRef)); batch.delete(delRef); // Insert entity to merge Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(baseEntity), options, null); addMergeToBatch(baseEntity, batch); ArrayList<TableResult> results = this.table.execute(batch); assertEquals(results.size(), 3); Iterator<TableResult> iter = results.iterator(); // insert assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // delete assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // merge assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); }
private void testBatchInsertOrMerge(TableRequestOptions options) throws StorageException { TableBatchOperation batch = new TableBatchOperation(); addInsertBatch(batch); // insert entity to delete Class1 delRef = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(delRef), options, null); batch.delete(delRef); // Insert entity to merge Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(baseEntity), options, null); addInsertOrMergeToBatch(baseEntity, batch); ArrayList<TableResult> results = this.table.execute(batch); assertEquals(results.size(), 3); Iterator<TableResult> iter = results.iterator(); // insert assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // delete assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // merge assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); }
private void testBatchReplace(TableRequestOptions options) throws StorageException { TableBatchOperation batch = new TableBatchOperation(); addInsertBatch(batch); // insert entity to delete Class1 delRef = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(delRef), options, null); batch.delete(delRef); // Insert entity to replace Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(baseEntity), options, null); addReplaceToBatch(baseEntity, batch); ArrayList<TableResult> results = this.table.execute(batch); assertEquals(results.size(), 3); Iterator<TableResult> iter = results.iterator(); // insert assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // delete assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // replace assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); }
private void testBatchInsertOrReplace(TableRequestOptions options) throws StorageException { TableBatchOperation batch = new TableBatchOperation(); addInsertBatch(batch); // insert entity to delete Class1 delRef = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(delRef), options, null); batch.delete(delRef); // Insert entity to replace Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(baseEntity), options, null); addInsertOrReplaceToBatch(baseEntity, batch); ArrayList<TableResult> results = this.table.execute(batch, options, null); assertEquals(results.size(), 3); Iterator<TableResult> iter = results.iterator(); // insert assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // delete assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // replace assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); }
private void testInsert(TableRequestOptions options) throws StorageException { Class1 ref = new Class1(); ref.setA("foo_A"); ref.setB("foo_B"); ref.setC("foo_C"); // 1mb right here ref.setD(new byte[1024]); ref.setPartitionKey("jxscl_odata"); ref.setRowKey("echo_default" + UUID.randomUUID().toString()); TableResult res = this.table.execute(TableOperation.insert(ref), options, null); assertEquals(HttpURLConnection.HTTP_NO_CONTENT, res.getHttpStatusCode()); ref.setRowKey("echo" + UUID.randomUUID().toString()); res = this.table.execute(TableOperation.insert(ref, true), options, null); assertEquals(HttpURLConnection.HTTP_CREATED, res.getHttpStatusCode()); ref.setRowKey("echo_off" + UUID.randomUUID().toString()); res = this.table.execute(TableOperation.insert(ref, false), options, null); assertEquals(HttpURLConnection.HTTP_NO_CONTENT, res.getHttpStatusCode()); }
@Test public void testInsertEmptyEntity() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); EmptyClass ref = new EmptyClass(); ref.setPartitionKey("jxscl_odata"); ref.setRowKey("echo_default" + UUID.randomUUID().toString()); TableResult res = this.table.execute(TableOperation.insert(ref), options, null); assertEquals(HttpURLConnection.HTTP_NO_CONTENT, res.getHttpStatusCode()); EmptyClassDynamic refDynamic = new EmptyClassDynamic(); refDynamic.setPartitionKey("jxscl_odata"); refDynamic.setRowKey("echo_default" + UUID.randomUUID().toString()); res = this.table.execute(TableOperation.insert(refDynamic), options, null); assertEquals(HttpURLConnection.HTTP_NO_CONTENT, res.getHttpStatusCode()); }
@Test public void testBatchEmptyQuery() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); // insert entity Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); TableBatchOperation batch = new TableBatchOperation(); batch.retrieve(ref.getPartitionKey(), ref.getRowKey(), ref.getClass()); ArrayList<TableResult> results = this.table.execute(batch, options, null); assertEquals(results.size(), 1); assertNull(results.get(0).getResult()); assertEquals(results.get(0).getHttpStatusCode(), HttpURLConnection.HTTP_NOT_FOUND); }
private void insertAndDeleteBatchWithX(int x, TableRequestOptions options) throws StorageException { TableBatchOperation batch = new TableBatchOperation(); for (int m = 0; m < x; m++) { addInsertBatch(batch); } TableBatchOperation delBatch = new TableBatchOperation(); ArrayList<TableResult> results = this.table.execute(batch, options, null); for (TableResult r : results) { assertEquals(r.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); delBatch.delete((Class1) r.getResult()); } ArrayList<TableResult> delResults = this.table.execute(delBatch, options, null); for (TableResult r : delResults) { assertEquals(r.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); } }
private void upsertAndDeleteBatchWithX(int x, TableRequestOptions options) throws StorageException { TableBatchOperation batch = new TableBatchOperation(); for (int m = 0; m < x; m++) { addInsertOrMergeToBatch(TableTestHelper.generateRandomEntity("jxscl_odata"), batch); } TableBatchOperation delBatch = new TableBatchOperation(); ArrayList<TableResult> results = this.table.execute(batch, options, null); for (TableResult r : results) { assertEquals(r.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); delBatch.delete((Class2) r.getResult()); } ArrayList<TableResult> delResults = this.table.execute(delBatch, options, null); for (TableResult r : delResults) { assertEquals(r.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); } }
assertEquals(HttpURLConnection.HTTP_NO_CONTENT, iter.next().getHttpStatusCode());
assertEquals(HttpURLConnection.HTTP_NO_CONTENT, iter.next().getHttpStatusCode());
private void testBatchRetrieve(TableRequestOptions options) throws StorageException { // insert entity Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(ref), options, null); TableBatchOperation batch = new TableBatchOperation(); batch.retrieve(ref.getPartitionKey(), ref.getRowKey(), ref.getClass()); ArrayList<TableResult> results = this.table.execute(batch, options, null); assertEquals(results.size(), 1); assertEquals(results.get(0).getHttpStatusCode(), HttpURLConnection.HTTP_OK); Class1 retrievedRef = results.get(0).getResultAsType(); assertEquals(ref.getA(), retrievedRef.getA()); assertEquals(ref.getB(), retrievedRef.getB()); assertEquals(ref.getC(), retrievedRef.getC()); assertTrue(Arrays.equals(ref.getD(), retrievedRef.getD())); this.table.execute(TableOperation.delete(ref), options, null); }
@Test public void testEmptyRetrieve() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); Class1 ref = new Class1(); ref.setA("foo_A"); ref.setB("foo_B"); ref.setC("foo_C"); ref.setD(new byte[]{0, 1, 2}); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); TableResult res = this.table.execute( TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), Class1.class), options, null); assertNull(res.getResult()); assertEquals(res.getHttpStatusCode(), HttpURLConnection.HTTP_NOT_FOUND); }
assertEquals(replaceResult.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); assertNotNull(replaceResult.getEtag());
private void testBatchDelete(TableRequestOptions options) throws StorageException { Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); // insert entity this.table.execute(TableOperation.insert(ref), options, null); TableBatchOperation batch = new TableBatchOperation(); batch.delete(ref); ArrayList<TableResult> delResults = this.table.execute(batch, options, null); for (TableResult r : delResults) { assertEquals(r.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); } try { this.table.execute(batch, options, null); fail(); } catch (StorageException ex) { assertEquals(ex.getHttpStatusCode(), HttpURLConnection.HTTP_NOT_FOUND); } }