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:51 UTC
[2/4] accumulo git commit: ACCUMULO-3624 Consolidate the duplciate
ScanIteratorIT classes.
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();
+
+ }
+
}