/** * Breaks the lease and ensures that another client cannot acquire a new lease until the current lease * period has expired. * * @param breakPeriodInSeconds * An <code>Integer</code> which specifies the time to wait, in seconds, until the current lease is * broken. * If null, the break period is the remainder of the current lease, or zero for infinite leases. * * @return The time, in seconds, remaining in the lease period. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final long breakLease(final Integer breakPeriodInSeconds) throws StorageException { return this.breakLease(breakPeriodInSeconds, null /* accessCondition */, null, null); }
/** * Breaks the lease and ensures that another client cannot acquire a new lease until the current lease * period has expired. * * @param breakPeriodInSeconds * An <code>Integer</code> which specifies the time to wait, in seconds, until the current lease is * broken. * If null, the break period is the remainder of the current lease, or zero for infinite leases. * * @return The time, in seconds, remaining in the lease period. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final long breakLease(final Integer breakPeriodInSeconds) throws StorageException { return this.breakLease(breakPeriodInSeconds, null /* accessCondition */, null, null); }
@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()); } }
@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); } }
this.container.breakLease(60); try { this.container.changeLease(proposedLeaseId2, AccessCondition.generateLeaseCondition(leaseID1)); this.container.breakLease(0); try { this.container.changeLease(proposedLeaseId, AccessCondition.generateLeaseCondition(leaseID1)); this.container.breakLease(0); try { this.container.changeLease(leaseID1, AccessCondition.generateLeaseCondition(leaseID1));