You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by el...@apache.org on 2015/09/30 17:12:50 UTC

[1/4] accumulo git commit: ACCUMULO-3624 Consolidate the duplciate ScanIteratorIT classes.

Repository: accumulo
Updated Branches:
  refs/heads/1.7 22b5258b3 -> f59218006
  refs/heads/master 0cbb1ea27 -> 82e9f0c56


ACCUMULO-3624 Consolidate the duplciate ScanIteratorIT classes.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/f5921800
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/f5921800
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/f5921800

Branch: refs/heads/1.7
Commit: f592180060b5f59b02c9671c973f4abe486d907d
Parents: 22b5258
Author: Josh Elser <el...@apache.org>
Authored: Tue Sep 29 16:55:40 2015 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Wed Sep 30 09:55:27 2015 -0400

----------------------------------------------------------------------
 .../apache/accumulo/test/ScanIteratorIT.java    | 170 -------------------
 .../test/functional/ScanIteratorIT.java         | 121 ++++++++++++-
 2 files changed, 119 insertions(+), 172 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/f5921800/test/src/test/java/org/apache/accumulo/test/ScanIteratorIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/ScanIteratorIT.java b/test/src/test/java/org/apache/accumulo/test/ScanIteratorIT.java
deleted file mode 100644
index 438279d..0000000
--- a/test/src/test/java/org/apache/accumulo/test/ScanIteratorIT.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.accumulo.test;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.apache.accumulo.cluster.ClusterUser;
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
-import org.apache.accumulo.core.client.BatchScanner;
-import org.apache.accumulo.core.client.BatchWriter;
-import org.apache.accumulo.core.client.BatchWriterConfig;
-import org.apache.accumulo.core.client.ClientConfiguration;
-import org.apache.accumulo.core.client.ClientConfiguration.ClientProperty;
-import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.IteratorSetting;
-import org.apache.accumulo.core.client.MutationsRejectedException;
-import org.apache.accumulo.core.client.Scanner;
-import org.apache.accumulo.core.client.ScannerBase;
-import org.apache.accumulo.core.client.TableNotFoundException;
-import org.apache.accumulo.core.client.security.tokens.PasswordToken;
-import org.apache.accumulo.core.data.Key;
-import org.apache.accumulo.core.data.Mutation;
-import org.apache.accumulo.core.data.Range;
-import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.core.security.Authorizations;
-import org.apache.accumulo.core.security.TablePermission;
-import org.apache.accumulo.harness.AccumuloClusterIT;
-import org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl;
-import org.apache.accumulo.test.functional.AuthsIterator;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.io.Text;
-import org.apache.hadoop.security.UserGroupInformation;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ScanIteratorIT extends AccumuloClusterIT {
-  private static final Logger log = LoggerFactory.getLogger(ScanIteratorIT.class);
-
-  @Override
-  public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSite) {
-    cfg.setNumTservers(1);
-  }
-
-  @Override
-  protected int defaultTimeoutSeconds() {
-    return 60;
-  }
-
-  private Connector connector;
-  private String tableName;
-  private String user;
-  private boolean saslEnabled;
-
-  @Before
-  public void setup() throws Exception {
-    connector = getConnector();
-    tableName = getUniqueNames(1)[0];
-
-    connector.tableOperations().create(tableName);
-    ClientConfiguration clientConfig = cluster.getClientConfig();
-    ClusterUser clusterUser = getUser(0);
-    user = clusterUser.getPrincipal();
-    PasswordToken userToken;
-    if (clientConfig.getBoolean(ClientProperty.INSTANCE_RPC_SASL_ENABLED.getKey(), false)) {
-      userToken = null;
-      saslEnabled = true;
-    } else {
-      userToken = new PasswordToken(clusterUser.getPassword());
-      saslEnabled = false;
-    }
-    if (connector.securityOperations().listLocalUsers().contains(user)) {
-      log.info("Dropping {}", user);
-      connector.securityOperations().dropLocalUser(user);
-    }
-    connector.securityOperations().createLocalUser(user, userToken);
-    connector.securityOperations().grantTablePermission(user, tableName, TablePermission.READ);
-    connector.securityOperations().grantTablePermission(user, tableName, TablePermission.WRITE);
-    connector.securityOperations().changeUserAuthorizations(user, AuthsIterator.AUTHS);
-  }
-
-  @After
-  public void tearDown() throws Exception {
-    if (null != user) {
-      if (saslEnabled) {
-        ClusterUser rootUser = getAdminUser();
-        UserGroupInformation.loginUserFromKeytab(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath());
-      }
-      connector.securityOperations().dropLocalUser(user);
-    }
-  }
-
-  @Test
-  public void testAuthsPresentInIteratorEnvironment() throws Exception {
-    runTest(AuthsIterator.AUTHS, false);
-  }
-
-  @Test
-  public void testAuthsNotPresentInIteratorEnvironment() throws Exception {
-    runTest(new Authorizations("B"), true);
-  }
-
-  @Test
-  public void testEmptyAuthsInIteratorEnvironment() throws Exception {
-    runTest(Authorizations.EMPTY, true);
-  }
-
-  private void runTest(ScannerBase scanner, Authorizations auths, boolean shouldFail) throws AccumuloSecurityException, AccumuloException,
-      TableNotFoundException {
-    int count = 0;
-    for (Map.Entry<Key,Value> entry : scanner) {
-      assertEquals(shouldFail ? AuthsIterator.FAIL : AuthsIterator.SUCCESS, entry.getKey().getRow().toString());
-      count++;
-    }
-
-    assertEquals(1, count);
-  }
-
-  private void runTest(Authorizations auths, boolean shouldFail) throws Exception {
-    ClusterUser clusterUser = getUser(0);
-    Connector userC = getCluster().getConnector(clusterUser.getPrincipal(), clusterUser.getToken());
-    writeTestMutation(userC);
-
-    IteratorSetting setting = new IteratorSetting(10, AuthsIterator.class);
-
-    Scanner scanner = userC.createScanner(tableName, auths);
-    scanner.addScanIterator(setting);
-
-    BatchScanner batchScanner = userC.createBatchScanner(tableName, auths, 1);
-    batchScanner.setRanges(Collections.singleton(new Range("1")));
-    batchScanner.addScanIterator(setting);
-
-    runTest(scanner, auths, shouldFail);
-    runTest(batchScanner, auths, shouldFail);
-
-    scanner.close();
-    batchScanner.close();
-  }
-
-  private void writeTestMutation(Connector userC) throws TableNotFoundException, MutationsRejectedException {
-    BatchWriter batchWriter = userC.createBatchWriter(tableName, new BatchWriterConfig());
-    Mutation m = new Mutation("1");
-    m.put(new Text("2"), new Text("3"), new Value("".getBytes()));
-    batchWriter.addMutation(m);
-    batchWriter.flush();
-    batchWriter.close();
-
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f5921800/test/src/test/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/ScanIteratorIT.java b/test/src/test/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
index 8c10199..74c4fd4 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
@@ -17,40 +17,100 @@
 package org.apache.accumulo.test.functional;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.Assert.assertEquals;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Map.Entry;
 
+import org.apache.accumulo.cluster.ClusterUser;
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.client.BatchScanner;
 import org.apache.accumulo.core.client.BatchWriter;
 import org.apache.accumulo.core.client.BatchWriterConfig;
+import org.apache.accumulo.core.client.ClientConfiguration;
+import org.apache.accumulo.core.client.ClientConfiguration.ClientProperty;
 import org.apache.accumulo.core.client.Connector;
 import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.MutationsRejectedException;
 import org.apache.accumulo.core.client.Scanner;
 import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Mutation;
 import org.apache.accumulo.core.data.Range;
 import org.apache.accumulo.core.data.Value;
 import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.security.TablePermission;
 import org.apache.accumulo.harness.AccumuloClusterIT;
+import org.apache.accumulo.test.functional.AuthsIterator;
 import org.apache.hadoop.io.Text;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ScanIteratorIT extends AccumuloClusterIT {
+  private static final Logger log = LoggerFactory.getLogger(ScanIteratorIT.class);
 
   @Override
   protected int defaultTimeoutSeconds() {
-    return 30;
+    return 60;
+  }
+
+  private Connector connector;
+  private String tableName;
+  private String user;
+  private boolean saslEnabled;
+
+  @Before
+  public void setup() throws Exception {
+    connector = getConnector();
+    tableName = getUniqueNames(1)[0];
+
+    connector.tableOperations().create(tableName);
+    ClientConfiguration clientConfig = cluster.getClientConfig();
+    ClusterUser clusterUser = getUser(0);
+    user = clusterUser.getPrincipal();
+    PasswordToken userToken;
+    if (clientConfig.getBoolean(ClientProperty.INSTANCE_RPC_SASL_ENABLED.getKey(), false)) {
+      userToken = null;
+      saslEnabled = true;
+    } else {
+      userToken = new PasswordToken(clusterUser.getPassword());
+      saslEnabled = false;
+    }
+    if (connector.securityOperations().listLocalUsers().contains(user)) {
+      log.info("Dropping {}", user);
+      connector.securityOperations().dropLocalUser(user);
+    }
+    connector.securityOperations().createLocalUser(user, userToken);
+    connector.securityOperations().grantTablePermission(user, tableName, TablePermission.READ);
+    connector.securityOperations().grantTablePermission(user, tableName, TablePermission.WRITE);
+    connector.securityOperations().changeUserAuthorizations(user, AuthsIterator.AUTHS);
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    if (null != user) {
+      if (saslEnabled) {
+        ClusterUser rootUser = getAdminUser();
+        UserGroupInformation.loginUserFromKeytab(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath());
+      }
+      connector.securityOperations().dropLocalUser(user);
+    }
   }
 
   @Test
   public void run() throws Exception {
     String tableName = getUniqueNames(1)[0];
     Connector c = getConnector();
-    c.tableOperations().create(tableName);
 
     BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
 
@@ -131,4 +191,61 @@ public class ScanIteratorIT extends AccumuloClusterIT {
     scanner.addScanIterator(dropMod);
   }
 
+  @Test
+  public void testAuthsPresentInIteratorEnvironment() throws Exception {
+    runTest(AuthsIterator.AUTHS, false);
+  }
+
+  @Test
+  public void testAuthsNotPresentInIteratorEnvironment() throws Exception {
+    runTest(new Authorizations("B"), true);
+  }
+
+  @Test
+  public void testEmptyAuthsInIteratorEnvironment() throws Exception {
+    runTest(Authorizations.EMPTY, true);
+  }
+
+  private void runTest(ScannerBase scanner, Authorizations auths, boolean shouldFail) throws AccumuloSecurityException, AccumuloException,
+      TableNotFoundException {
+    int count = 0;
+    for (Map.Entry<Key,Value> entry : scanner) {
+      assertEquals(shouldFail ? AuthsIterator.FAIL : AuthsIterator.SUCCESS, entry.getKey().getRow().toString());
+      count++;
+    }
+
+    assertEquals(1, count);
+  }
+
+  private void runTest(Authorizations auths, boolean shouldFail) throws Exception {
+    ClusterUser clusterUser = getUser(0);
+    Connector userC = getCluster().getConnector(clusterUser.getPrincipal(), clusterUser.getToken());
+    writeTestMutation(userC);
+
+    IteratorSetting setting = new IteratorSetting(10, AuthsIterator.class);
+
+    Scanner scanner = userC.createScanner(tableName, auths);
+    scanner.addScanIterator(setting);
+
+    BatchScanner batchScanner = userC.createBatchScanner(tableName, auths, 1);
+    batchScanner.setRanges(Collections.singleton(new Range("1")));
+    batchScanner.addScanIterator(setting);
+
+    runTest(scanner, auths, shouldFail);
+    runTest(batchScanner, auths, shouldFail);
+
+    scanner.close();
+    batchScanner.close();
+  }
+
+  private void writeTestMutation(Connector userC) throws TableNotFoundException, MutationsRejectedException {
+    BatchWriter batchWriter = userC.createBatchWriter(tableName, new BatchWriterConfig());
+    Mutation m = new Mutation("1");
+    m.put(new Text("2"), new Text("3"), new Value("".getBytes()));
+    batchWriter.addMutation(m);
+    batchWriter.flush();
+    batchWriter.close();
+
+  }
+
 }


[4/4] accumulo git commit: ACCUMULO-4002 Fix findbugs warning.

Posted by el...@apache.org.
ACCUMULO-4002 Fix findbugs warning.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/82e9f0c5
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/82e9f0c5
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/82e9f0c5

Branch: refs/heads/master
Commit: 82e9f0c5661e33e5dad7d725864b40e932d3931d
Parents: 1a2232a
Author: Josh Elser <el...@apache.org>
Authored: Wed Sep 30 09:57:07 2015 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Wed Sep 30 09:57:07 2015 -0400

----------------------------------------------------------------------
 .../org/apache/accumulo/test/functional/ConfigurableMacBase.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/82e9f0c5/test/src/main/java/org/apache/accumulo/test/functional/ConfigurableMacBase.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/functional/ConfigurableMacBase.java b/test/src/main/java/org/apache/accumulo/test/functional/ConfigurableMacBase.java
index 92424a8..85246bf 100644
--- a/test/src/main/java/org/apache/accumulo/test/functional/ConfigurableMacBase.java
+++ b/test/src/main/java/org/apache/accumulo/test/functional/ConfigurableMacBase.java
@@ -146,7 +146,7 @@ public class ConfigurableMacBase extends AccumuloITBase {
       OutputStream out = new BufferedOutputStream(new FileOutputStream(tmp));
       coreSite.writeXml(out);
       out.close();
-      tmp.renameTo(csFile);
+      assertTrue(tmp.renameTo(csFile));
     }
     beforeClusterStart(cfg);
   }


[2/4] accumulo git commit: ACCUMULO-3624 Consolidate the duplciate ScanIteratorIT classes.

Posted by el...@apache.org.
ACCUMULO-3624 Consolidate the duplciate ScanIteratorIT classes.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/f5921800
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/f5921800
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/f5921800

Branch: refs/heads/master
Commit: f592180060b5f59b02c9671c973f4abe486d907d
Parents: 22b5258
Author: Josh Elser <el...@apache.org>
Authored: Tue Sep 29 16:55:40 2015 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Wed Sep 30 09:55:27 2015 -0400

----------------------------------------------------------------------
 .../apache/accumulo/test/ScanIteratorIT.java    | 170 -------------------
 .../test/functional/ScanIteratorIT.java         | 121 ++++++++++++-
 2 files changed, 119 insertions(+), 172 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/f5921800/test/src/test/java/org/apache/accumulo/test/ScanIteratorIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/ScanIteratorIT.java b/test/src/test/java/org/apache/accumulo/test/ScanIteratorIT.java
deleted file mode 100644
index 438279d..0000000
--- a/test/src/test/java/org/apache/accumulo/test/ScanIteratorIT.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.accumulo.test;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.apache.accumulo.cluster.ClusterUser;
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
-import org.apache.accumulo.core.client.BatchScanner;
-import org.apache.accumulo.core.client.BatchWriter;
-import org.apache.accumulo.core.client.BatchWriterConfig;
-import org.apache.accumulo.core.client.ClientConfiguration;
-import org.apache.accumulo.core.client.ClientConfiguration.ClientProperty;
-import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.IteratorSetting;
-import org.apache.accumulo.core.client.MutationsRejectedException;
-import org.apache.accumulo.core.client.Scanner;
-import org.apache.accumulo.core.client.ScannerBase;
-import org.apache.accumulo.core.client.TableNotFoundException;
-import org.apache.accumulo.core.client.security.tokens.PasswordToken;
-import org.apache.accumulo.core.data.Key;
-import org.apache.accumulo.core.data.Mutation;
-import org.apache.accumulo.core.data.Range;
-import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.core.security.Authorizations;
-import org.apache.accumulo.core.security.TablePermission;
-import org.apache.accumulo.harness.AccumuloClusterIT;
-import org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl;
-import org.apache.accumulo.test.functional.AuthsIterator;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.io.Text;
-import org.apache.hadoop.security.UserGroupInformation;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ScanIteratorIT extends AccumuloClusterIT {
-  private static final Logger log = LoggerFactory.getLogger(ScanIteratorIT.class);
-
-  @Override
-  public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSite) {
-    cfg.setNumTservers(1);
-  }
-
-  @Override
-  protected int defaultTimeoutSeconds() {
-    return 60;
-  }
-
-  private Connector connector;
-  private String tableName;
-  private String user;
-  private boolean saslEnabled;
-
-  @Before
-  public void setup() throws Exception {
-    connector = getConnector();
-    tableName = getUniqueNames(1)[0];
-
-    connector.tableOperations().create(tableName);
-    ClientConfiguration clientConfig = cluster.getClientConfig();
-    ClusterUser clusterUser = getUser(0);
-    user = clusterUser.getPrincipal();
-    PasswordToken userToken;
-    if (clientConfig.getBoolean(ClientProperty.INSTANCE_RPC_SASL_ENABLED.getKey(), false)) {
-      userToken = null;
-      saslEnabled = true;
-    } else {
-      userToken = new PasswordToken(clusterUser.getPassword());
-      saslEnabled = false;
-    }
-    if (connector.securityOperations().listLocalUsers().contains(user)) {
-      log.info("Dropping {}", user);
-      connector.securityOperations().dropLocalUser(user);
-    }
-    connector.securityOperations().createLocalUser(user, userToken);
-    connector.securityOperations().grantTablePermission(user, tableName, TablePermission.READ);
-    connector.securityOperations().grantTablePermission(user, tableName, TablePermission.WRITE);
-    connector.securityOperations().changeUserAuthorizations(user, AuthsIterator.AUTHS);
-  }
-
-  @After
-  public void tearDown() throws Exception {
-    if (null != user) {
-      if (saslEnabled) {
-        ClusterUser rootUser = getAdminUser();
-        UserGroupInformation.loginUserFromKeytab(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath());
-      }
-      connector.securityOperations().dropLocalUser(user);
-    }
-  }
-
-  @Test
-  public void testAuthsPresentInIteratorEnvironment() throws Exception {
-    runTest(AuthsIterator.AUTHS, false);
-  }
-
-  @Test
-  public void testAuthsNotPresentInIteratorEnvironment() throws Exception {
-    runTest(new Authorizations("B"), true);
-  }
-
-  @Test
-  public void testEmptyAuthsInIteratorEnvironment() throws Exception {
-    runTest(Authorizations.EMPTY, true);
-  }
-
-  private void runTest(ScannerBase scanner, Authorizations auths, boolean shouldFail) throws AccumuloSecurityException, AccumuloException,
-      TableNotFoundException {
-    int count = 0;
-    for (Map.Entry<Key,Value> entry : scanner) {
-      assertEquals(shouldFail ? AuthsIterator.FAIL : AuthsIterator.SUCCESS, entry.getKey().getRow().toString());
-      count++;
-    }
-
-    assertEquals(1, count);
-  }
-
-  private void runTest(Authorizations auths, boolean shouldFail) throws Exception {
-    ClusterUser clusterUser = getUser(0);
-    Connector userC = getCluster().getConnector(clusterUser.getPrincipal(), clusterUser.getToken());
-    writeTestMutation(userC);
-
-    IteratorSetting setting = new IteratorSetting(10, AuthsIterator.class);
-
-    Scanner scanner = userC.createScanner(tableName, auths);
-    scanner.addScanIterator(setting);
-
-    BatchScanner batchScanner = userC.createBatchScanner(tableName, auths, 1);
-    batchScanner.setRanges(Collections.singleton(new Range("1")));
-    batchScanner.addScanIterator(setting);
-
-    runTest(scanner, auths, shouldFail);
-    runTest(batchScanner, auths, shouldFail);
-
-    scanner.close();
-    batchScanner.close();
-  }
-
-  private void writeTestMutation(Connector userC) throws TableNotFoundException, MutationsRejectedException {
-    BatchWriter batchWriter = userC.createBatchWriter(tableName, new BatchWriterConfig());
-    Mutation m = new Mutation("1");
-    m.put(new Text("2"), new Text("3"), new Value("".getBytes()));
-    batchWriter.addMutation(m);
-    batchWriter.flush();
-    batchWriter.close();
-
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f5921800/test/src/test/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/ScanIteratorIT.java b/test/src/test/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
index 8c10199..74c4fd4 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
@@ -17,40 +17,100 @@
 package org.apache.accumulo.test.functional;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.Assert.assertEquals;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Map.Entry;
 
+import org.apache.accumulo.cluster.ClusterUser;
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.client.BatchScanner;
 import org.apache.accumulo.core.client.BatchWriter;
 import org.apache.accumulo.core.client.BatchWriterConfig;
+import org.apache.accumulo.core.client.ClientConfiguration;
+import org.apache.accumulo.core.client.ClientConfiguration.ClientProperty;
 import org.apache.accumulo.core.client.Connector;
 import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.MutationsRejectedException;
 import org.apache.accumulo.core.client.Scanner;
 import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Mutation;
 import org.apache.accumulo.core.data.Range;
 import org.apache.accumulo.core.data.Value;
 import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.security.TablePermission;
 import org.apache.accumulo.harness.AccumuloClusterIT;
+import org.apache.accumulo.test.functional.AuthsIterator;
 import org.apache.hadoop.io.Text;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ScanIteratorIT extends AccumuloClusterIT {
+  private static final Logger log = LoggerFactory.getLogger(ScanIteratorIT.class);
 
   @Override
   protected int defaultTimeoutSeconds() {
-    return 30;
+    return 60;
+  }
+
+  private Connector connector;
+  private String tableName;
+  private String user;
+  private boolean saslEnabled;
+
+  @Before
+  public void setup() throws Exception {
+    connector = getConnector();
+    tableName = getUniqueNames(1)[0];
+
+    connector.tableOperations().create(tableName);
+    ClientConfiguration clientConfig = cluster.getClientConfig();
+    ClusterUser clusterUser = getUser(0);
+    user = clusterUser.getPrincipal();
+    PasswordToken userToken;
+    if (clientConfig.getBoolean(ClientProperty.INSTANCE_RPC_SASL_ENABLED.getKey(), false)) {
+      userToken = null;
+      saslEnabled = true;
+    } else {
+      userToken = new PasswordToken(clusterUser.getPassword());
+      saslEnabled = false;
+    }
+    if (connector.securityOperations().listLocalUsers().contains(user)) {
+      log.info("Dropping {}", user);
+      connector.securityOperations().dropLocalUser(user);
+    }
+    connector.securityOperations().createLocalUser(user, userToken);
+    connector.securityOperations().grantTablePermission(user, tableName, TablePermission.READ);
+    connector.securityOperations().grantTablePermission(user, tableName, TablePermission.WRITE);
+    connector.securityOperations().changeUserAuthorizations(user, AuthsIterator.AUTHS);
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    if (null != user) {
+      if (saslEnabled) {
+        ClusterUser rootUser = getAdminUser();
+        UserGroupInformation.loginUserFromKeytab(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath());
+      }
+      connector.securityOperations().dropLocalUser(user);
+    }
   }
 
   @Test
   public void run() throws Exception {
     String tableName = getUniqueNames(1)[0];
     Connector c = getConnector();
-    c.tableOperations().create(tableName);
 
     BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
 
@@ -131,4 +191,61 @@ public class ScanIteratorIT extends AccumuloClusterIT {
     scanner.addScanIterator(dropMod);
   }
 
+  @Test
+  public void testAuthsPresentInIteratorEnvironment() throws Exception {
+    runTest(AuthsIterator.AUTHS, false);
+  }
+
+  @Test
+  public void testAuthsNotPresentInIteratorEnvironment() throws Exception {
+    runTest(new Authorizations("B"), true);
+  }
+
+  @Test
+  public void testEmptyAuthsInIteratorEnvironment() throws Exception {
+    runTest(Authorizations.EMPTY, true);
+  }
+
+  private void runTest(ScannerBase scanner, Authorizations auths, boolean shouldFail) throws AccumuloSecurityException, AccumuloException,
+      TableNotFoundException {
+    int count = 0;
+    for (Map.Entry<Key,Value> entry : scanner) {
+      assertEquals(shouldFail ? AuthsIterator.FAIL : AuthsIterator.SUCCESS, entry.getKey().getRow().toString());
+      count++;
+    }
+
+    assertEquals(1, count);
+  }
+
+  private void runTest(Authorizations auths, boolean shouldFail) throws Exception {
+    ClusterUser clusterUser = getUser(0);
+    Connector userC = getCluster().getConnector(clusterUser.getPrincipal(), clusterUser.getToken());
+    writeTestMutation(userC);
+
+    IteratorSetting setting = new IteratorSetting(10, AuthsIterator.class);
+
+    Scanner scanner = userC.createScanner(tableName, auths);
+    scanner.addScanIterator(setting);
+
+    BatchScanner batchScanner = userC.createBatchScanner(tableName, auths, 1);
+    batchScanner.setRanges(Collections.singleton(new Range("1")));
+    batchScanner.addScanIterator(setting);
+
+    runTest(scanner, auths, shouldFail);
+    runTest(batchScanner, auths, shouldFail);
+
+    scanner.close();
+    batchScanner.close();
+  }
+
+  private void writeTestMutation(Connector userC) throws TableNotFoundException, MutationsRejectedException {
+    BatchWriter batchWriter = userC.createBatchWriter(tableName, new BatchWriterConfig());
+    Mutation m = new Mutation("1");
+    m.put(new Text("2"), new Text("3"), new Value("".getBytes()));
+    batchWriter.addMutation(m);
+    batchWriter.flush();
+    batchWriter.close();
+
+  }
+
 }


[3/4] accumulo git commit: Merge branch '1.7'

Posted by el...@apache.org.
Merge branch '1.7'

Conflicts:
	test/src/main/java/org/apache/accumulo/test/ScanIteratorIT.java
	test/src/main/java/org/apache/accumulo/test/functional/ScanIteratorIT.java


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/1a2232a1
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/1a2232a1
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/1a2232a1

Branch: refs/heads/master
Commit: 1a2232a1504e23cca8c74c9523d94d5e3eda8217
Parents: 0cbb1ea f592180
Author: Josh Elser <el...@apache.org>
Authored: Wed Sep 30 09:56:40 2015 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Wed Sep 30 09:56:40 2015 -0400

----------------------------------------------------------------------
 .../apache/accumulo/test/ScanIteratorIT.java    | 170 -------------------
 .../test/functional/ScanIteratorIT.java         | 121 ++++++++++++-
 2 files changed, 119 insertions(+), 172 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/1a2232a1/test/src/main/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
----------------------------------------------------------------------
diff --cc test/src/main/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
index 3453303,0000000..eb6b5e3
mode 100644,000000..100644
--- a/test/src/main/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
@@@ -1,134 -1,0 +1,251 @@@
 +/*
 + * Licensed to the Apache Software Foundation (ASF) under one or more
 + * contributor license agreements.  See the NOTICE file distributed with
 + * this work for additional information regarding copyright ownership.
 + * The ASF licenses this file to You under the Apache License, Version 2.0
 + * (the "License"); you may not use this file except in compliance with
 + * the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.accumulo.test.functional;
 +
 +import static java.nio.charset.StandardCharsets.UTF_8;
++import static org.junit.Assert.assertEquals;
 +
 +import java.util.ArrayList;
 +import java.util.Collections;
 +import java.util.HashSet;
++import java.util.Map;
 +import java.util.Map.Entry;
 +
++import org.apache.accumulo.cluster.ClusterUser;
++import org.apache.accumulo.core.client.AccumuloException;
++import org.apache.accumulo.core.client.AccumuloSecurityException;
 +import org.apache.accumulo.core.client.BatchScanner;
 +import org.apache.accumulo.core.client.BatchWriter;
 +import org.apache.accumulo.core.client.BatchWriterConfig;
++import org.apache.accumulo.core.client.ClientConfiguration;
++import org.apache.accumulo.core.client.ClientConfiguration.ClientProperty;
 +import org.apache.accumulo.core.client.Connector;
 +import org.apache.accumulo.core.client.IteratorSetting;
++import org.apache.accumulo.core.client.MutationsRejectedException;
 +import org.apache.accumulo.core.client.Scanner;
 +import org.apache.accumulo.core.client.ScannerBase;
++import org.apache.accumulo.core.client.TableNotFoundException;
++import org.apache.accumulo.core.client.security.tokens.PasswordToken;
 +import org.apache.accumulo.core.data.Key;
 +import org.apache.accumulo.core.data.Mutation;
 +import org.apache.accumulo.core.data.Range;
 +import org.apache.accumulo.core.data.Value;
 +import org.apache.accumulo.core.security.Authorizations;
 +import org.apache.accumulo.harness.AccumuloClusterHarness;
++import org.apache.accumulo.core.security.TablePermission;
++import org.apache.accumulo.test.functional.AuthsIterator;
 +import org.apache.hadoop.io.Text;
++import org.apache.hadoop.security.UserGroupInformation;
++import org.junit.After;
++import org.junit.Before;
 +import org.junit.Test;
++import org.slf4j.Logger;
++import org.slf4j.LoggerFactory;
 +
 +public class ScanIteratorIT extends AccumuloClusterHarness {
++  private static final Logger log = LoggerFactory.getLogger(ScanIteratorIT.class);
 +
 +  @Override
 +  protected int defaultTimeoutSeconds() {
-     return 30;
++    return 60;
++  }
++
++  private Connector connector;
++  private String tableName;
++  private String user;
++  private boolean saslEnabled;
++
++  @Before
++  public void setup() throws Exception {
++    connector = getConnector();
++    tableName = getUniqueNames(1)[0];
++
++    connector.tableOperations().create(tableName);
++    ClientConfiguration clientConfig = cluster.getClientConfig();
++    ClusterUser clusterUser = getUser(0);
++    user = clusterUser.getPrincipal();
++    PasswordToken userToken;
++    if (clientConfig.getBoolean(ClientProperty.INSTANCE_RPC_SASL_ENABLED.getKey(), false)) {
++      userToken = null;
++      saslEnabled = true;
++    } else {
++      userToken = new PasswordToken(clusterUser.getPassword());
++      saslEnabled = false;
++    }
++    if (connector.securityOperations().listLocalUsers().contains(user)) {
++      log.info("Dropping {}", user);
++      connector.securityOperations().dropLocalUser(user);
++    }
++    connector.securityOperations().createLocalUser(user, userToken);
++    connector.securityOperations().grantTablePermission(user, tableName, TablePermission.READ);
++    connector.securityOperations().grantTablePermission(user, tableName, TablePermission.WRITE);
++    connector.securityOperations().changeUserAuthorizations(user, AuthsIterator.AUTHS);
++  }
++
++  @After
++  public void tearDown() throws Exception {
++    if (null != user) {
++      if (saslEnabled) {
++        ClusterUser rootUser = getAdminUser();
++        UserGroupInformation.loginUserFromKeytab(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath());
++      }
++      connector.securityOperations().dropLocalUser(user);
++    }
 +  }
 +
 +  @Test
 +  public void run() throws Exception {
 +    String tableName = getUniqueNames(1)[0];
 +    Connector c = getConnector();
-     c.tableOperations().create(tableName);
 +
 +    BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
 +
 +    for (int i = 0; i < 1000; i++) {
 +      Mutation m = new Mutation(new Text(String.format("%06d", i)));
 +      m.put(new Text("cf1"), new Text("cq1"), new Value(Integer.toString(1000 - i).getBytes(UTF_8)));
 +      m.put(new Text("cf1"), new Text("cq2"), new Value(Integer.toString(i - 1000).getBytes(UTF_8)));
 +
 +      bw.addMutation(m);
 +    }
 +
 +    bw.close();
 +
 +    Scanner scanner = c.createScanner(tableName, new Authorizations());
 +
 +    setupIter(scanner);
 +    verify(scanner, 1, 999);
 +
 +    BatchScanner bscanner = c.createBatchScanner(tableName, new Authorizations(), 3);
 +    bscanner.setRanges(Collections.singleton(new Range((Key) null, null)));
 +
 +    setupIter(bscanner);
 +    verify(bscanner, 1, 999);
 +
 +    ArrayList<Range> ranges = new ArrayList<Range>();
 +    ranges.add(new Range(new Text(String.format("%06d", 1))));
 +    ranges.add(new Range(new Text(String.format("%06d", 6)), new Text(String.format("%06d", 16))));
 +    ranges.add(new Range(new Text(String.format("%06d", 20))));
 +    ranges.add(new Range(new Text(String.format("%06d", 23))));
 +    ranges.add(new Range(new Text(String.format("%06d", 56)), new Text(String.format("%06d", 61))));
 +    ranges.add(new Range(new Text(String.format("%06d", 501)), new Text(String.format("%06d", 504))));
 +    ranges.add(new Range(new Text(String.format("%06d", 998)), new Text(String.format("%06d", 1000))));
 +
 +    HashSet<Integer> got = new HashSet<Integer>();
 +    HashSet<Integer> expected = new HashSet<Integer>();
 +    for (int i : new int[] {1, 7, 9, 11, 13, 15, 23, 57, 59, 61, 501, 503, 999}) {
 +      expected.add(i);
 +    }
 +
 +    bscanner.setRanges(ranges);
 +
 +    for (Entry<Key,Value> entry : bscanner) {
 +      got.add(Integer.parseInt(entry.getKey().getRow().toString()));
 +    }
 +
 +    System.out.println("got : " + got);
 +
 +    if (!got.equals(expected)) {
 +      throw new Exception(got + " != " + expected);
 +    }
 +
 +    bscanner.close();
 +
 +  }
 +
 +  private void verify(Iterable<Entry<Key,Value>> scanner, int start, int finish) throws Exception {
 +
 +    int expected = start;
 +    for (Entry<Key,Value> entry : scanner) {
 +      if (Integer.parseInt(entry.getKey().getRow().toString()) != expected) {
 +        throw new Exception("Saw unexpexted " + entry.getKey().getRow() + " " + expected);
 +      }
 +
 +      if (entry.getKey().getColumnQualifier().toString().equals("cq2")) {
 +        expected += 2;
 +      }
 +    }
 +
 +    if (expected != finish + 2) {
 +      throw new Exception("Ended at " + expected + " not " + (finish + 2));
 +    }
 +  }
 +
 +  private void setupIter(ScannerBase scanner) throws Exception {
 +    IteratorSetting dropMod = new IteratorSetting(50, "dropMod", "org.apache.accumulo.test.functional.DropModIter");
 +    dropMod.addOption("mod", "2");
 +    dropMod.addOption("drop", "0");
 +    scanner.addScanIterator(dropMod);
 +  }
 +
++  @Test
++  public void testAuthsPresentInIteratorEnvironment() throws Exception {
++    runTest(AuthsIterator.AUTHS, false);
++  }
++
++  @Test
++  public void testAuthsNotPresentInIteratorEnvironment() throws Exception {
++    runTest(new Authorizations("B"), true);
++  }
++
++  @Test
++  public void testEmptyAuthsInIteratorEnvironment() throws Exception {
++    runTest(Authorizations.EMPTY, true);
++  }
++
++  private void runTest(ScannerBase scanner, Authorizations auths, boolean shouldFail) throws AccumuloSecurityException, AccumuloException,
++      TableNotFoundException {
++    int count = 0;
++    for (Map.Entry<Key,Value> entry : scanner) {
++      assertEquals(shouldFail ? AuthsIterator.FAIL : AuthsIterator.SUCCESS, entry.getKey().getRow().toString());
++      count++;
++    }
++
++    assertEquals(1, count);
++  }
++
++  private void runTest(Authorizations auths, boolean shouldFail) throws Exception {
++    ClusterUser clusterUser = getUser(0);
++    Connector userC = getCluster().getConnector(clusterUser.getPrincipal(), clusterUser.getToken());
++    writeTestMutation(userC);
++
++    IteratorSetting setting = new IteratorSetting(10, AuthsIterator.class);
++
++    Scanner scanner = userC.createScanner(tableName, auths);
++    scanner.addScanIterator(setting);
++
++    BatchScanner batchScanner = userC.createBatchScanner(tableName, auths, 1);
++    batchScanner.setRanges(Collections.singleton(new Range("1")));
++    batchScanner.addScanIterator(setting);
++
++    runTest(scanner, auths, shouldFail);
++    runTest(batchScanner, auths, shouldFail);
++
++    scanner.close();
++    batchScanner.close();
++  }
++
++  private void writeTestMutation(Connector userC) throws TableNotFoundException, MutationsRejectedException {
++    BatchWriter batchWriter = userC.createBatchWriter(tableName, new BatchWriterConfig());
++    Mutation m = new Mutation("1");
++    m.put(new Text("2"), new Text("3"), new Value("".getBytes()));
++    batchWriter.addMutation(m);
++    batchWriter.flush();
++    batchWriter.close();
++
++  }
++
 +}