/** * Acquires a new infinite lease on the container. * * @return A <code>String</code> that represents the lease ID. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final String acquireLease() throws StorageException { return this.acquireLease(null /* leaseTimeInSeconds */, null /* proposedLeaseId */); }
/** * Acquires a new infinite lease on the container. * * @return A <code>String</code> that represents the lease ID. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final String acquireLease() throws StorageException { return this.acquireLease(null /* leaseTimeInSeconds */, null /* proposedLeaseId */); }
/** * Acquires a new lease on the container with the specified lease time and proposed lease ID. * * @param leaseTimeInSeconds * An <code>Integer</code> which specifies the span of time for which to acquire the lease, in seconds. * If null, an infinite lease will be acquired. If not null, the value must be greater than * zero. * * @param proposedLeaseId * A <code>String</code> that represents the proposed lease ID for the new lease, * or null if no lease ID is proposed. * * @return A <code>String</code> that represents the lease ID. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final String acquireLease(final Integer leaseTimeInSeconds, final String proposedLeaseId) throws StorageException { return this.acquireLease(leaseTimeInSeconds, proposedLeaseId, null /* accessCondition */, null /* options */, null /* opContext */); }
/** * Acquires a new lease on the container with the specified lease time and proposed lease ID. * * @param leaseTimeInSeconds * An <code>Integer</code> which specifies the span of time for which to acquire the lease, in seconds. * If null, an infinite lease will be acquired. If not null, the value must be greater than * zero. * * @param proposedLeaseId * A <code>String</code> that represents the proposed lease ID for the new lease, * or null if no lease ID is proposed. * * @return A <code>String</code> that represents the lease ID. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final String acquireLease(final Integer leaseTimeInSeconds, final String proposedLeaseId) throws StorageException { return this.acquireLease(leaseTimeInSeconds, proposedLeaseId, null /* accessCondition */, null /* options */, null /* opContext */); }
@Test public void testContainerReleaseLease() throws StorageException { // 15 sec String proposedLeaseId = UUID.randomUUID().toString(); String leaseId = this.container.acquireLease(15, proposedLeaseId); AccessCondition condition = new AccessCondition(); condition.setLeaseID(leaseId); OperationContext operationContext1 = new OperationContext(); this.container.releaseLease(condition, null/* BlobRequestOptions */, operationContext1); assertTrue(operationContext1.getLastResult().getStatusCode() == HttpURLConnection.HTTP_OK); // infinite leaseId = this.container.acquireLease(); condition = new AccessCondition(); condition.setLeaseID(leaseId); OperationContext operationContext2 = new OperationContext(); this.container.releaseLease(condition, null/* BlobRequestOptions */, operationContext2); assertTrue(operationContext2.getLastResult().getStatusCode() == HttpURLConnection.HTTP_OK); }
@Test public void testContainerLeaseInvalidParams() throws StorageException, URISyntaxException { try { this.container.acquireLease(100, null); } catch(StorageException ex) { assertEquals("The value of the parameter 'leaseTimeInSeconds' should be between 15 and 60.", ex.getMessage()); } try { this.container.breakLease(100); } catch(StorageException ex) { assertEquals("The value of the parameter 'breakPeriodInSeconds' should be between 0 and 60.", ex.getMessage()); } }
leaseContainer1.acquireLease(15, proposedLeaseId1, null /*access condition*/, String leaseId2; OperationContext operationContext2 = new OperationContext(); leaseId1 = leaseContainer2.acquireLease(null /* infinite lease */, proposedLeaseId2, null /*access condition*/, null/* BlobRequestOptions */, operationContext2); assertTrue(operationContext2.getLastResult().getStatusCode() == HttpURLConnection.HTTP_CREATED); leaseId2 = leaseContainer2.acquireLease(null /* infinite lease */, proposedLeaseId2); assertEquals(leaseId1, leaseId2);
@Test @Category(SlowTests.class) public void testContainerBreakLease() throws StorageException, InterruptedException { String proposedLeaseId = UUID.randomUUID().toString(); try { // 5 sec this.container.acquireLease(15, proposedLeaseId); AccessCondition condition = new AccessCondition(); condition.setLeaseID(proposedLeaseId); OperationContext operationContext1 = new OperationContext(); this.container.breakLease(0, condition, null/* BlobRequestOptions */, operationContext1); assertTrue(operationContext1.getLastResult().getStatusCode() == HttpURLConnection.HTTP_ACCEPTED); Thread.sleep(15 * 1000); // infinite proposedLeaseId = this.container.acquireLease(); condition = new AccessCondition(); condition.setLeaseID(proposedLeaseId); OperationContext operationContext2 = new OperationContext(); this.container.breakLease(0, condition, null/* BlobRequestOptions */, operationContext2); assertTrue(operationContext2.getLastResult().getStatusCode() == HttpURLConnection.HTTP_ACCEPTED); } finally { // cleanup AccessCondition condition = new AccessCondition(); condition.setLeaseID(proposedLeaseId); this.container.releaseLease(condition); } }
leaseID1 = this.container.acquireLease(null /* infinite lease */, null /*proposed lease id */, null /*access condition*/, null/* BlobRequestOptions */, operationContext); assertTrue(operationContext.getLastResult().getStatusCode() == HttpURLConnection.HTTP_CREATED); leaseID1 = this.container.acquireLease(null /* infinite lease */, null /*proposed lease id */, null /*access condition*/, null/* BlobRequestOptions */, operationContext); this.container.breakLease(60); leaseID1 = this.container.acquireLease(null /* infinite lease */, null /*proposed lease id */, null /*access condition*/, null/* BlobRequestOptions */, operationContext); this.container.breakLease(0);
@Test public void testContainerRenewLeaseTest() throws StorageException{ String proposedLeaseId = UUID.randomUUID().toString(); try { // 5 sec this.container.acquireLease(15, proposedLeaseId); AccessCondition condition = new AccessCondition(); condition.setLeaseID(proposedLeaseId); OperationContext operationContext1 = new OperationContext(); this.container.renewLease(condition, null/* BlobRequestOptions */, operationContext1); assertTrue(operationContext1.getLastResult().getStatusCode() == HttpURLConnection.HTTP_OK); this.container.releaseLease(condition); // infinite proposedLeaseId = this.container.acquireLease(); condition = new AccessCondition(); condition.setLeaseID(proposedLeaseId); OperationContext operationContext2 = new OperationContext(); this.container.renewLease(condition, null/* BlobRequestOptions */, operationContext2); assertTrue(operationContext2.getLastResult().getStatusCode() == HttpURLConnection.HTTP_OK); } finally { // cleanup AccessCondition condition = new AccessCondition(); condition.setLeaseID(proposedLeaseId); this.container.releaseLease(condition); } }