@Test @Category( {CloudTests.class }) public void testGetServiceStats() throws StorageException { CloudTableClient tClient = TableTestHelper.createCloudTableClient(); tClient.getDefaultRequestOptions().setLocationMode(LocationMode.SECONDARY_ONLY); TableTestHelper.verifyServiceStats(tClient.getServiceStats()); } }
options.setLocationMode(LocationMode.PRIMARY_ONLY); table.createIfNotExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.PRIMARY_THEN_SECONDARY); table.createIfNotExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.SECONDARY_THEN_PRIMARY); table.createIfNotExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.SECONDARY_ONLY); try { table.createIfNotExists(options, context); options.setLocationMode(LocationMode.PRIMARY_ONLY); table.deleteIfExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.PRIMARY_THEN_SECONDARY); table.deleteIfExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.SECONDARY_THEN_PRIMARY); table.deleteIfExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.SECONDARY_ONLY);
private static void testTableDownloadPermissions(LocationMode optionsLocationMode, LocationMode clientLocationMode, StorageLocation initialLocation, List<RetryContext> retryContextList, List<RetryInfo> retryInfoList) throws URISyntaxException, StorageException { CloudTableClient client = TestHelper.createCloudTableClient(); CloudTable table = client.getTableReference(TableTestHelper.generateRandomTableName()); MultiLocationTestHelper helper = new MultiLocationTestHelper(table.getServiceClient().getStorageUri(), initialLocation, retryContextList, retryInfoList); table.getServiceClient().getDefaultRequestOptions().setLocationMode(clientLocationMode); TableRequestOptions options = new TableRequestOptions(); options.setLocationMode(optionsLocationMode); options.setRetryPolicyFactory(helper.retryPolicy); try { table.downloadPermissions(options, helper.operationContext); } catch (StorageException ex) { assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ex.getHttpStatusCode()); } finally { helper.close(); } } }
@Test // don't need the category secondary as the request will fail before being sent public void testBatchSecondaryWriteShouldThrow() { // create batch with an insert Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); TableOperation op = TableOperation.insert(baseEntity); TableBatchOperation batch = new TableBatchOperation(); batch.add(op); // should not be able to make a request to secondary as there are writes try { TableRequestOptions options = new TableRequestOptions(); options.setLocationMode(LocationMode.SECONDARY_ONLY); options.setRetryPolicyFactory(new RetryNoRetry()); this.table.execute(batch, options, null); fail("Should not be able to make a request to secondary as there are writes."); } catch (StorageException e) { assertEquals(IllegalArgumentException.class, e.getCause().getClass()); assertEquals(SR.PRIMARY_ONLY_COMMAND, e.getCause().getMessage()); } }
@Test @Category(SecondaryTests.class) public void testBatchSecondaryNoWrite() throws StorageException { // create and insert an entity Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(ref)); // create a batch and add a query for this entity TableBatchOperation batch = new TableBatchOperation(); TableOperation queryOp = TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), ref.getClass()); batch.add(queryOp); // should be able to make a request to secondary as there are no writes TableRequestOptions options = new TableRequestOptions(); options.setLocationMode(LocationMode.SECONDARY_ONLY); options.setRetryPolicyFactory(new RetryNoRetry()); this.table.execute(batch, options, null); }
tableClient.getDefaultRequestOptions().setLocationMode(LocationMode.PRIMARY_THEN_SECONDARY); tableClient.getDefaultRequestOptions().setTimeoutIntervalInMs(1000); tableClient.getDefaultRequestOptions().setTablePayloadFormat(TablePayloadFormat.JsonNoMetadata);