// two distinct Namenodes
String nn1 = DelegationTokenRenewal.SCHEME + "://host1:0";
String nn2 = DelegationTokenRenewal.SCHEME + "://host2:0";
String nn3 = DelegationTokenRenewal.SCHEME + "://host3:0";
Credentials ts = new Credentials();
// register the token for renewal
ts.addToken(new Text(nn1), token1);
ts.addToken(new Text(nn2), token2);
ts.addToken(new Text(nn3), token3);
// register the tokens for renewal
DelegationTokenRenewal.registerDelegationTokensForRenewal(
new JobID("job1", 1), ts, conf);
// first 3 initial renewals + 1 real
int numberOfExpectedRenewals = 3+1;
int attempts = 10;
while(attempts-- > 0) {
try {
Thread.sleep(3*1000); // sleep 3 seconds, so it has time to renew
} catch (InterruptedException e) {}
// since we cannot guarantee timely execution - let's give few chances
if(dfs.getCounter()==numberOfExpectedRenewals)
break;
}
System.out.println("Counter = " + dfs.getCounter() + ";t="+
dfs.getToken());
assertEquals("renew wasn't called as many times as expected(4):",
numberOfExpectedRenewals, dfs.getCounter());
assertEquals("most recently renewed token mismatch", dfs.getToken(),
token1);
// Test 2.
// add another token ( that expires in 2 secs). Then remove it, before
// time is up.
// Wait for 3 secs , and make sure no renews were called
ts = new Credentials();
MyToken token4 = dfs.getDelegationToken(new Text("user4"));
//to cause this one to be set for renew in 2 secs
dfs.setTokenToRenewIn2Sec(token4);
System.out.println("token="+token4+" should be renewed for 2 secs");
String nn4 = DelegationTokenRenewal.SCHEME + "://host4:0";
ts.addToken(new Text(nn4), token4);
JobID jid2 = new JobID("job2",1);
DelegationTokenRenewal.registerDelegationTokensForRenewal(jid2, ts, conf);
DelegationTokenRenewal.removeDelegationTokenRenewalForJob(jid2);