This is an automated email from the ASF dual-hosted git repository. domgarguilo pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push: new f64b55c46a Attempt to make KerberosRenewalIT more stable (#2902) f64b55c46a is described below commit f64b55c46afd8636c9112200aedba49ebaaa8726 Author: Dom G <dominic.gargu...@gmail.com> AuthorDate: Fri Sep 9 13:22:28 2022 -0400 Attempt to make KerberosRenewalIT more stable (#2902) * Simplify timeout in while-loop * Add wait for table delete * Add AccumuloClient to try-with-resources block * Move start of timer after tablename creation Co-authored-by: Dave Marion <dlmar...@apache.org> --- .../test/functional/KerberosRenewalIT.java | 77 +++++++++------------- 1 file changed, 32 insertions(+), 45 deletions(-) diff --git a/test/src/main/java/org/apache/accumulo/test/functional/KerberosRenewalIT.java b/test/src/main/java/org/apache/accumulo/test/functional/KerberosRenewalIT.java index cc4c1539f5..ab4e0d395c 100644 --- a/test/src/main/java/org/apache/accumulo/test/functional/KerberosRenewalIT.java +++ b/test/src/main/java/org/apache/accumulo/test/functional/KerberosRenewalIT.java @@ -28,12 +28,8 @@ import java.util.Map.Entry; import org.apache.accumulo.cluster.ClusterUser; import org.apache.accumulo.core.client.AccumuloClient; -import org.apache.accumulo.core.client.AccumuloException; -import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.BatchWriter; import org.apache.accumulo.core.client.Scanner; -import org.apache.accumulo.core.client.TableExistsException; -import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.admin.CompactionConfig; import org.apache.accumulo.core.client.security.tokens.KerberosToken; import org.apache.accumulo.core.client.security.tokens.PasswordToken; @@ -45,11 +41,10 @@ import org.apache.accumulo.core.data.PartialKey; import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.security.Authorizations; import org.apache.accumulo.harness.AccumuloITBase; -import org.apache.accumulo.harness.MiniClusterConfigurationCallback; import org.apache.accumulo.harness.MiniClusterHarness; import org.apache.accumulo.harness.TestingKdc; import org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl; -import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl; +import org.apache.accumulo.test.util.Wait; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.CommonConfigurationKeysPublic; import org.apache.hadoop.minikdc.MiniKdc; @@ -94,7 +89,7 @@ public class KerberosRenewalIT extends AccumuloITBase { new TestingKdc(TestingKdc.computeKdcDir(), TestingKdc.computeKeytabDir(), TICKET_LIFETIME); kdc.start(); krbEnabledForITs = System.getProperty(MiniClusterHarness.USE_KERBEROS_FOR_IT_OPTION); - if (krbEnabledForITs == null || !Boolean.parseBoolean(krbEnabledForITs)) { + if (!Boolean.parseBoolean(krbEnabledForITs)) { System.setProperty(MiniClusterHarness.USE_KERBEROS_FOR_IT_OPTION, "true"); } rootUser = kdc.getRootUser(); @@ -115,19 +110,14 @@ public class KerberosRenewalIT extends AccumuloITBase { @BeforeEach public void startMac() throws Exception { MiniClusterHarness harness = new MiniClusterHarness(); - mac = harness.create(this, new PasswordToken("unused"), kdc, - new MiniClusterConfigurationCallback() { - - @Override - public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration coreSite) { - Map<String,String> site = cfg.getSiteConfig(); - site.put(Property.INSTANCE_ZK_TIMEOUT.getKey(), "15s"); - // Reduce the period just to make sure we trigger renewal fast - site.put(Property.GENERAL_KERBEROS_RENEWAL_PERIOD.getKey(), "5s"); - cfg.setSiteConfig(site); - cfg.setClientProperty(ClientProperty.INSTANCE_ZOOKEEPERS_TIMEOUT, "15s"); - } - }); + mac = harness.create(this, new PasswordToken("unused"), kdc, (cfg, coreSite) -> { + Map<String,String> site = cfg.getSiteConfig(); + site.put(Property.INSTANCE_ZK_TIMEOUT.getKey(), "15s"); + // Reduce the period just to make sure we trigger renewal fast + site.put(Property.GENERAL_KERBEROS_RENEWAL_PERIOD.getKey(), "5s"); + cfg.setSiteConfig(site); + cfg.setClientProperty(ClientProperty.INSTANCE_ZOOKEEPERS_TIMEOUT, "15s"); + }); mac.getConfig().setNumTservers(1); mac.start(); @@ -159,23 +149,20 @@ public class KerberosRenewalIT extends AccumuloITBase { rootUser.getKeytab().getAbsolutePath()); log.info("Logged in as {}", rootUser.getPrincipal()); - AccumuloClient client = mac.createAccumuloClient(rootUser.getPrincipal(), new KerberosToken()); - log.info("Created client as {}", rootUser.getPrincipal()); - assertEquals(rootUser.getPrincipal(), client.whoami()); - - long duration = 0; - long last = System.currentTimeMillis(); - // Make sure we have a couple renewals happen - while (duration < TICKET_TEST_LIFETIME) { - // Create a table, write a record, compact, read the record, drop the table. - createReadWriteDrop(client); - // Wait a bit after - Thread.sleep(5000); - - // Update the duration - long now = System.currentTimeMillis(); - duration += now - last; - last = now; + try (var client = mac.createAccumuloClient(rootUser.getPrincipal(), new KerberosToken())) { + log.info("Created client as {}", rootUser.getPrincipal()); + assertEquals(rootUser.getPrincipal(), client.whoami()); + + final String tableName = getUniqueNames(1)[0] + "_table"; + long endTime = System.currentTimeMillis() + TICKET_TEST_LIFETIME; + + // Make sure we have a couple renewals happen + while (System.currentTimeMillis() < endTime) { + // Create a table, write a record, compact, read the record, drop the table. + createReadWriteDrop(client, tableName); + // Wait a bit after + Thread.sleep(5000L); + } } } @@ -184,23 +171,23 @@ public class KerberosRenewalIT extends AccumuloITBase { * that the system user exists (since the manager does an RPC to the tserver which will create the * system user if it doesn't already exist). */ - private void createReadWriteDrop(AccumuloClient client) throws TableNotFoundException, - AccumuloSecurityException, AccumuloException, TableExistsException { - final String table = testName() + "_table"; - client.tableOperations().create(table); - try (BatchWriter bw = client.createBatchWriter(table)) { + private void createReadWriteDrop(AccumuloClient client, String tableName) throws Exception { + client.tableOperations().create(tableName); + try (BatchWriter bw = client.createBatchWriter(tableName)) { Mutation m = new Mutation("a"); m.put("b", "c", "d"); bw.addMutation(m); } - client.tableOperations().compact(table, new CompactionConfig().setFlush(true).setWait(true)); - try (Scanner s = client.createScanner(table, Authorizations.EMPTY)) { + client.tableOperations().compact(tableName, + new CompactionConfig().setFlush(true).setWait(true)); + try (Scanner s = client.createScanner(tableName, Authorizations.EMPTY)) { Entry<Key,Value> entry = getOnlyElement(s); assertEquals(0, new Key("a", "b", "c").compareTo(entry.getKey(), PartialKey.ROW_COLFAM_COLQUAL), "Did not find the expected key"); assertEquals("d", entry.getValue().toString()); - client.tableOperations().delete(table); } + client.tableOperations().delete(tableName); + Wait.waitFor(() -> !client.tableOperations().exists(tableName), 20_000L, 200L); } }