Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,9 @@ private void unsyncSetGraceSleepPeriod(final long gracePeriod) {
half: LEASE_RENEWER_SLEEP_DEFAULT;
}

@VisibleForTesting
/** Is the daemon running? */
synchronized boolean isRunning() {
public synchronized boolean isRunning() {
return daemon != null && daemon.isAlive();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,14 @@ public void testLeaseRenewSocketTimeout() throws Exception
Mockito.anyString());
DFSClient client = new DFSClient(null, spyNN, conf, null);
// Get hold of the lease renewer instance used by the client
LeaseRenewer leaseRenewer = client.getLeaseRenewer();
leaseRenewer.setRenewalTime(100);
final LeaseRenewer leaseRenewer1 = client.getLeaseRenewer();
leaseRenewer1.setRenewalTime(100);
OutputStream out1 = client.create(file1, false);

Mockito.verify(spyNN, timeout(10000).times(1)).renewLease(
Mockito.anyString());
verifyEmptyLease(leaseRenewer);
verifyEmptyLease(leaseRenewer1);
GenericTestUtils.waitFor(() -> !(leaseRenewer1.isRunning()), 100, 10000);
try {
out1.write(new byte[256]);
fail("existing output stream should be aborted");
Expand All @@ -406,14 +407,14 @@ public void testLeaseRenewSocketTimeout() throws Exception
// throws SocketTimeoutException.
Mockito.doNothing().when(spyNN).renewLease(
Mockito.anyString());
leaseRenewer = client.getLeaseRenewer();
leaseRenewer.setRenewalTime(100);
LeaseRenewer leaseRenewer2 = client.getLeaseRenewer();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we set final to leaseRenewer2 as well as leaseRenewer1?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm +1 if that is addressed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I addressed your comment. Thanks.

leaseRenewer2.setRenewalTime(100);
OutputStream out2 = client.create(file2, false);
Mockito.verify(spyNN, timeout(10000).times(2)).renewLease(
Mockito.anyString());
out2.write(new byte[256]);
out2.close();
verifyEmptyLease(leaseRenewer);
verifyEmptyLease(leaseRenewer2);
} finally {
cluster.shutdown();
}
Expand Down Expand Up @@ -758,11 +759,7 @@ private boolean busyTest(int xcievers, int threads, int fileLen, int timeWin, in
}

private void verifyEmptyLease(LeaseRenewer leaseRenewer) throws Exception {
int sleepCount = 0;
while (!leaseRenewer.isEmpty() && sleepCount++ < 20) {
Thread.sleep(500);
}
assertTrue("Lease should be empty.", leaseRenewer.isEmpty());
GenericTestUtils.waitFor(() -> leaseRenewer.isEmpty(), 100, 10000);
}

class DFSClientReader implements Runnable {
Expand Down