Author: ecn
Date: Wed Jan 23 16:57:00 2013
New Revision: 1437567
URL: http://svn.apache.org/viewvc?rev=1437567&view=rev
Log:
ACCUMULO-983 moved proxy tests into proxy package
Added:
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java
(with props)
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyInstanceOperations.java
(with props)
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyReadWrite.java
(with props)
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxySecurityOperations.java
(with props)
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyTableOperations.java
(with props)
Added:
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java?rev=1437567&view=auto
==============================================================================
---
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java
(added)
+++
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java
Wed Jan 23 16:57:00 2013
@@ -0,0 +1,303 @@
+package org.apache.accumulo.proxy;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Random;
+import java.util.Set;
+
+import org.apache.accumulo.core.iterators.DevNull;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.util.UtilWaitThread;
+import org.apache.accumulo.proxy.thrift.AccumuloProxy.Client;
+import org.apache.accumulo.proxy.thrift.PActiveCompaction;
+import org.apache.accumulo.proxy.thrift.PActiveScan;
+import org.apache.accumulo.proxy.thrift.PColumnUpdate;
+import org.apache.accumulo.proxy.thrift.PCompactionReason;
+import org.apache.accumulo.proxy.thrift.PCompactionType;
+import org.apache.accumulo.proxy.thrift.PIteratorScope;
+import org.apache.accumulo.proxy.thrift.PIteratorSetting;
+import org.apache.accumulo.proxy.thrift.PScanState;
+import org.apache.accumulo.proxy.thrift.PScanType;
+import org.apache.accumulo.proxy.thrift.PSystemPermission;
+import org.apache.accumulo.proxy.thrift.PTablePermission;
+import org.apache.accumulo.proxy.thrift.PTimeType;
+import org.apache.accumulo.proxy.thrift.UserPass;
+import org.apache.accumulo.server.test.functional.SlowIterator;
+import org.apache.accumulo.test.MiniAccumuloCluster;
+import org.apache.thrift.TException;
+import org.apache.thrift.server.TServer;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+/**
+ * An example unit test that shows how to use MiniAccumuloCluster in a unit
test
+ */
+
+public class SimpleTest {
+
+ public static TemporaryFolder folder = new TemporaryFolder();
+
+ private static MiniAccumuloCluster accumulo;
+ private static String secret = "superSecret";
+ private static Random random = new Random();
+ private static TServer proxyServer;
+ private static Thread thread;
+ private static int proxyPort;
+ private static org.apache.accumulo.proxy.thrift.AccumuloProxy.Client client;
+ private static UserPass creds = new UserPass("root",
ByteBuffer.wrap(secret.getBytes()));
+
+ @BeforeClass
+ public static void setupMiniCluster() throws Exception {
+ folder.create();
+ accumulo = new MiniAccumuloCluster(folder.getRoot(), secret);
+ accumulo.start();
+
+ Properties props = new Properties();
+ props.put("org.apache.accumulo.proxy.ProxyServer.instancename",
accumulo.getInstanceName());
+ props.put("org.apache.accumulo.proxy.ProxyServer.zookeepers",
accumulo.getZookeepers());
+
+ proxyPort = 40000 + random.nextInt(20000);
+ proxyServer = Proxy.createProxyServer(
+ org.apache.accumulo.proxy.thrift.AccumuloProxy.class,
+ org.apache.accumulo.proxy.ProxyServer.class,
+ proxyPort,
+ props);
+ thread = new Thread() {
+ @Override
+ public void run() {
+ proxyServer.serve();
+ }
+ };
+ thread.start();
+ while (!proxyServer.isServing())
+ UtilWaitThread.sleep(100);
+ client = new TestProxyClient("localhost", proxyPort).proxy();
+ }
+
+ //@Test(timeout = 10000)
+ public void testPing() throws Exception {
+ client.ping(creds);
+ }
+
+ //@Test(timeout = 10000)
+ public void testInstanceOperations() throws Exception {
+ int tservers = 0;
+ for (String tserver : client.instanceOperations_getTabletServers(creds)) {
+ client.instanceOperations_pingTabletServer(creds, tserver);
+ tservers++;
+ }
+ assertTrue(tservers > 0);
+
+ // get something we know is in the site config
+ Map<String,String> cfg =
client.instanceOperations_getSiteConfiguration(creds);
+ assertTrue(cfg.get("instance.dfs.dir").startsWith("/tmp/junit"));
+
+ // set a property in zookeeper
+ client.instanceOperations_setProperty(creds, "table.split.threshold",
"500M");
+
+ // check that we can read it
+ cfg = client.instanceOperations_getSystemConfiguration(creds);
+ assertEquals("500M", cfg.get("table.split.threshold"));
+
+ // unset the setting, check that it's not what it was
+ client.instanceOperations_removeProperty(creds, "table.split.threshold");
+ cfg = client.instanceOperations_getSystemConfiguration(creds);
+ assertNotEquals("500M", cfg.get("table.split.threshold"));
+
+ // try to load some classes via the proxy
+ assertTrue(client.instanceOperations_testClassLoad(creds,
DevNull.class.getName(), SortedKeyValueIterator.class.getName()));
+ assertFalse(client.instanceOperations_testClassLoad(creds, "foo.bar",
SortedKeyValueIterator.class.getName()));
+
+ // create a table that's very slow, so we can look for scans/compactions
+ client.tableOperations_create(creds, "slow", true, PTimeType.MILLIS);
+ PIteratorSetting setting = new PIteratorSetting(100, "slow",
SlowIterator.class.getName(), Collections.singletonMap("sleepTime", "100"));
+ client.tableOperations_attachIterator(creds, "slow", setting,
EnumSet.allOf(PIteratorScope.class));
+ client.updateAndFlush(creds, "slow", mutation("row", "cf", "cq", "value"));
+ client.updateAndFlush(creds, "slow", mutation("row2", "cf", "cq",
"value"));
+ client.updateAndFlush(creds, "slow", mutation("row3", "cf", "cq",
"value"));
+ client.updateAndFlush(creds, "slow", mutation("row4", "cf", "cq",
"value"));
+
+ // scan
+ Thread t = new Thread() {
+ @Override
+ public void run() {
+ String scanner;
+ try {
+ Client client2 = new TestProxyClient("localhost", proxyPort).proxy();
+ scanner = client2.createScanner(creds, "slow", null, null, null);
+ client2.scanner_next_k(scanner, 10);
+ client2.close_scanner(scanner);
+ } catch (TException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ t.start();
+ // look for the scan
+ List<PActiveScan> scans = Collections.emptyList();
+ loop:
+ for (int i = 0; i < 100; i++) {
+ for (String tserver: client.instanceOperations_getTabletServers(creds)) {
+ scans = client.instanceOperations_getActiveScans(creds, tserver);
+ if (!scans.isEmpty())
+ break loop;
+ UtilWaitThread.sleep(10);
+ }
+ }
+ t.join();
+ assertFalse(scans.isEmpty());
+ PActiveScan scan = scans.get(0);
+ assertEquals("root", scan.getUser());
+ assertEquals(PScanState.RUNNING, scan.getState());
+ assertEquals(PScanType.SINGLE, scan.getType());
+ assertEquals("slow", scan.getTable());
+ Map<String,String> map = client.tableOperations_tableIdMap(creds);
+ assertEquals(map.get("slow"), scan.getExtent().tableId);
+ assertTrue(scan.getExtent().endRow == null);
+ assertTrue(scan.getExtent().prevEndRow == null);
+
+ // start a compaction
+ t = new Thread() {
+ @Override
+ public void run() {
+ try {
+ Client client2 = new TestProxyClient("localhost", proxyPort).proxy();
+ client2.tableOperations_compact(creds, "slow", null, null, null,
true, true);
+ } catch (TException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ t.start();
+
+ // try to catch it in the act
+ List<PActiveCompaction> compactions = Collections.emptyList();
+ loop2:
+ for (int i = 0; i < 100; i++) {
+ for (String tserver: client.instanceOperations_getTabletServers(creds)) {
+ compactions = client.instanceOperations_getActiveCompactions(creds,
tserver);
+ if (!compactions.isEmpty())
+ break loop2;
+ }
+ UtilWaitThread.sleep(10);
+ }
+ t.join();
+ // verify the compaction information
+ assertFalse(compactions.isEmpty());
+ PActiveCompaction c = compactions.get(0);
+ assertEquals(map.get("slow"), c.getExtent().tableId);
+ assertTrue(c.inputFiles.isEmpty());
+ assertEquals(PCompactionType.MINOR, c.getType());
+ assertEquals(PCompactionReason.USER, c.getReason());
+ assertEquals("", c.localityGroup);
+ assertTrue(c.outputFile.contains("default_tablet"));
+ }
+
+ @Test
+ public void testSecurityOperations() throws Exception {
+ // check password
+ assertTrue(client.securityOperations_authenticateUser(creds, "root",
s2bb(secret)));
+ assertFalse(client.securityOperations_authenticateUser(creds, "root",
s2bb("")));
+
+ // create a user
+ client.securityOperations_createUser(creds, "stooge", s2bb("password"));
+ // change auths
+ Set<String> users = client.securityOperations_listUsers(creds);
+ assertEquals(new HashSet<String>(Arrays.asList("root", "stooge")), users);
+ HashSet<ByteBuffer> auths = new
HashSet<ByteBuffer>(Arrays.asList(s2bb("A"),s2bb("B")));
+ client.securityOperations_changeUserAuthorizations(creds, "stooge", auths);
+ List<ByteBuffer> update =
client.securityOperations_getUserAuthorizations(creds, "stooge");
+ assertEquals(auths, new HashSet<ByteBuffer>(update));
+
+ // change password
+ client.securityOperations_changeUserPassword(creds, "stooge", s2bb(""));
+ assertTrue(client.securityOperations_authenticateUser(creds, "stooge",
s2bb("")));
+
+ // check permission failure
+ UserPass stooge = new UserPass("stooge", s2bb(""));
+ try {
+ client.tableOperations_create(stooge, "fail", true, PTimeType.MILLIS);
+ fail("should not create the table");
+ } catch (TException ex) {
+ assertFalse(client.tableOperations_list(creds).contains("fail"));
+ }
+ // grant permissions and test
+ assertFalse(client.securityOperations_hasSystemPermission(creds, "stooge",
PSystemPermission.CREATE_TABLE));
+ client.securityOperations_grantSystemPermission(creds, "stooge",
PSystemPermission.CREATE_TABLE);
+ assertTrue(client.securityOperations_hasSystemPermission(creds, "stooge",
PSystemPermission.CREATE_TABLE));
+ client.tableOperations_create(stooge, "success", true, PTimeType.MILLIS);
+ client.tableOperations_list(creds).contains("succcess");
+
+ // revoke permissions
+ client.securityOperations_revokeSystemPermission(creds, "stooge",
PSystemPermission.CREATE_TABLE);
+ assertFalse(client.securityOperations_hasSystemPermission(creds, "stooge",
PSystemPermission.CREATE_TABLE));
+ try {
+ client.tableOperations_create(stooge, "fail", true, PTimeType.MILLIS);
+ fail("should not create the table");
+ } catch (TException ex) {
+ assertFalse(client.tableOperations_list(creds).contains("fail"));
+ }
+ // create a table to test table permissions
+ client.tableOperations_create(creds, "test", true, PTimeType.MILLIS);
+ // denied!
+ try {
+ String scanner = client.createScanner(stooge, "test", null, null, null);
+ client.scanner_next_k(scanner, 100);
+ fail("stooge should not read table test");
+ } catch (TException ex) {
+ }
+ // grant
+ assertFalse(client.securityOperations_hasTablePermission(creds, "stooge",
"test", PTablePermission.READ));
+ client.securityOperations_grantTablePermission(creds, "stooge", "test",
PTablePermission.READ);
+ assertTrue(client.securityOperations_hasTablePermission(creds, "stooge",
"test", PTablePermission.READ));
+ String scanner = client.createScanner(stooge, "test", null, null, null);
+ client.scanner_next_k(scanner, 10);
+ client.close_scanner(scanner);
+ // revoke
+ client.securityOperations_revokeTablePermission(creds, "stooge", "test",
PTablePermission.READ);
+ assertFalse(client.securityOperations_hasTablePermission(creds, "stooge",
"test", PTablePermission.READ));
+ try {
+ scanner = client.createScanner(stooge, "test", null, null, null);
+ client.scanner_next_k(scanner, 100);
+ fail("stooge should not read table test");
+ } catch (TException ex) {
+ }
+
+ // delete user
+ client.securityOperations_dropUser(creds, "stooge");
+ users = client.securityOperations_listUsers(creds);
+ assertEquals(1, users.size());
+
+ }
+
+ private Map<ByteBuffer,List<PColumnUpdate>> mutation(String row, String cf,
String cq, String value) {
+ PColumnUpdate upd = new PColumnUpdate(s2bb(cf), s2bb(cq));
+ upd.setValue(value.getBytes());
+ return Collections.singletonMap(s2bb(row), Collections.singletonList(upd));
+ }
+
+ private ByteBuffer s2bb(String cf) {
+ return ByteBuffer.wrap(cf.getBytes());
+ }
+
+ @AfterClass
+ public static void tearDownMiniCluster() throws Exception {
+ accumulo.stop();
+ folder.delete();
+ }
+
+}
Propchange:
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyInstanceOperations.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyInstanceOperations.java?rev=1437567&view=auto
==============================================================================
---
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyInstanceOperations.java
(added)
+++
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyInstanceOperations.java
Wed Jan 23 16:57:00 2013
@@ -0,0 +1,82 @@
+/*
+ * 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.proxy;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.ByteBuffer;
+import java.util.Properties;
+
+import org.apache.accumulo.proxy.Proxy;
+import org.apache.accumulo.proxy.TestProxyClient;
+import org.apache.accumulo.proxy.thrift.UserPass;
+import org.apache.thrift.TException;
+import org.apache.thrift.server.TServer;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestProxyInstanceOperations {
+ protected static TServer proxy;
+ protected static Thread thread;
+ protected static TestProxyClient tpc;
+ protected static UserPass userpass;
+ protected static final int port = 10197;
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ Properties prop = new Properties();
+ prop.setProperty("org.apache.accumulo.proxy.ProxyServer.useMockInstance",
"true");
+
+ proxy =
Proxy.createProxyServer(Class.forName("org.apache.accumulo.proxy.thrift.AccumuloProxy"),
+ Class.forName("org.apache.accumulo.proxy.ProxyServer"), port, prop);
+ thread = new Thread() {
+ @Override
+ public void run() {
+ proxy.serve();
+ }
+ };
+ thread.start();
+ tpc = new TestProxyClient("localhost", port);
+ userpass = new UserPass("root", ByteBuffer.wrap("".getBytes()));
+ }
+
+ @AfterClass
+ public static void tearDown() throws InterruptedException {
+ proxy.stop();
+ thread.join();
+ }
+
+ @Test
+ public void properties() throws TException {
+ tpc.proxy().instanceOperations_setProperty(userpass, "test.systemprop",
"whistletips");
+
+
assertEquals(tpc.proxy().instanceOperations_getSystemConfiguration(userpass).get("test.systemprop"),
"whistletips");
+ tpc.proxy().instanceOperations_removeProperty(userpass, "test.systemprop");
+
assertNull(tpc.proxy().instanceOperations_getSystemConfiguration(userpass).get("test.systemprop"));
+
+ }
+
+ @Test
+ public void testClassLoad() throws TException {
+ assertTrue(tpc.proxy().instanceOperations_testClassLoad(userpass,
"org.apache.accumulo.core.iterators.user.RegExFilter",
+ "org.apache.accumulo.core.iterators.Filter"));
+ }
+
+}
Propchange:
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyInstanceOperations.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyReadWrite.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyReadWrite.java?rev=1437567&view=auto
==============================================================================
---
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyReadWrite.java
(added)
+++
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyReadWrite.java
Wed Jan 23 16:57:00 2013
@@ -0,0 +1,391 @@
+/*
+ * 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.proxy;
+
+import static org.junit.Assert.assertEquals;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.iterators.user.RegExFilter;
+import org.apache.accumulo.proxy.Proxy;
+import org.apache.accumulo.proxy.TestProxyClient;
+import org.apache.accumulo.proxy.Util;
+import org.apache.accumulo.proxy.thrift.PColumnUpdate;
+import org.apache.accumulo.proxy.thrift.PIteratorSetting;
+import org.apache.accumulo.proxy.thrift.PKey;
+import org.apache.accumulo.proxy.thrift.PKeyValue;
+import org.apache.accumulo.proxy.thrift.PRange;
+import org.apache.accumulo.proxy.thrift.PScanResult;
+import org.apache.accumulo.proxy.thrift.PTimeType;
+import org.apache.accumulo.proxy.thrift.UserPass;
+import org.apache.thrift.server.TServer;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestProxyReadWrite {
+ protected static TServer proxy;
+ protected static Thread thread;
+ protected static TestProxyClient tpc;
+ protected static UserPass userpass;
+ protected static final int port = 10194;
+ protected static final String testtable = "testtable";
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ Properties prop = new Properties();
+ prop.setProperty("org.apache.accumulo.proxy.ProxyServer.useMockInstance",
"true");
+
+ proxy =
Proxy.createProxyServer(Class.forName("org.apache.accumulo.proxy.thrift.AccumuloProxy"),
+ Class.forName("org.apache.accumulo.proxy.ProxyServer"), port, prop);
+ thread = new Thread() {
+ @Override
+ public void run() {
+ proxy.serve();
+ }
+ };
+ thread.start();
+ tpc = new TestProxyClient("localhost", port);
+ userpass = new UserPass("root", ByteBuffer.wrap("".getBytes()));
+ }
+
+ @AfterClass
+ public static void tearDown() throws InterruptedException {
+ proxy.stop();
+ thread.join();
+ }
+
+ @Before
+ public void makeTestTable() throws Exception {
+ tpc.proxy().tableOperations_create(userpass, testtable, true,
PTimeType.MILLIS);
+ }
+
+ @After
+ public void deleteTestTable() throws Exception {
+ tpc.proxy().tableOperations_delete(userpass, testtable);
+ }
+
+ private static void addMutation(Map<ByteBuffer,List<PColumnUpdate>>
mutations, String row, String cf, String cq, String value) {
+ PColumnUpdate update = new PColumnUpdate(ByteBuffer.wrap(cf.getBytes()),
ByteBuffer.wrap(cq.getBytes()));
+ update.setValue(value.getBytes());
+ mutations.put(ByteBuffer.wrap(row.getBytes()),
Collections.singletonList(update));
+ }
+
+ private static void addMutation(Map<ByteBuffer,List<PColumnUpdate>>
mutations, String row, String cf, String cq, String vis, String value) {
+ PColumnUpdate update = new PColumnUpdate(ByteBuffer.wrap(cf.getBytes()),
ByteBuffer.wrap(cq.getBytes()));
+ update.setValue(value.getBytes());
+ update.setColVisibility(vis.getBytes());
+ mutations.put(ByteBuffer.wrap(row.getBytes()),
Collections.singletonList(update));
+ }
+
+ /**
+ * Insert 100000 cells which have as the row [0..99999] (padded with zeros).
Set a range so only the entries between -Inf...5 come back (there should be
+ * 50,000)
+ *
+ * @throws Exception
+ */
+ @Test
+ public void readWriteBatchOneShotWithRange() throws Exception {
+ int maxInserts = 100000;
+ Map<ByteBuffer,List<PColumnUpdate>> mutations = new
HashMap<ByteBuffer,List<PColumnUpdate>>();
+ String format = "%1$05d";
+ for (int i = 0; i < maxInserts; i++) {
+ addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i,
Util.randString(10));
+
+ if (i % 1000 == 0 || i == maxInserts - 1) {
+ tpc.proxy().updateAndFlush(userpass, testtable, mutations);
+ mutations.clear();
+ }
+ }
+
+ PKey stop = new PKey();
+ stop.setRow("5".getBytes());
+ List<PRange> pranges = new ArrayList<PRange>();
+ pranges.add(new PRange(null, false, stop, false));
+ String cookie = tpc.proxy().createBatchScanner(userpass, testtable, null,
null, pranges);
+
+ int i = 0;
+ boolean hasNext = true;
+
+ int k = 1000;
+ while (hasNext) {
+ PScanResult kvList = tpc.proxy().scanner_next_k(cookie, k);
+ i += kvList.getResultsSize();
+ hasNext = kvList.isMore();
+ }
+ assertEquals(i, 50000);
+ }
+
+ /**
+ * Insert 100000 cells which have as the row [0..99999] (padded with zeros).
Filter the results so only the even numbers come back.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void readWriteBatchOneShotWithFilterIterator() throws Exception {
+ int maxInserts = 10000;
+ Map<ByteBuffer,List<PColumnUpdate>> mutations = new
HashMap<ByteBuffer,List<PColumnUpdate>>();
+ String format = "%1$05d";
+ for (int i = 0; i < maxInserts; i++) {
+ addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i,
Util.randString(10));
+
+ if (i % 1000 == 0 || i == maxInserts - 1) {
+ tpc.proxy().updateAndFlush(userpass, testtable, mutations);
+ mutations.clear();
+ }
+
+ }
+
+ String regex = ".*[02468]";
+
+ IteratorSetting is = new IteratorSetting(50, regex, RegExFilter.class);
+ RegExFilter.setRegexs(is, regex, null, null, null, false);
+
+ PIteratorSetting pis = Util.iteratorSetting2ProxyIteratorSetting(is);
+ String cookie = tpc.proxy().createBatchScanner(userpass, testtable, null,
Collections.singletonList(pis), null);
+
+ int i = 0;
+ boolean hasNext = true;
+
+ int k = 1000;
+ while (hasNext) {
+ PScanResult kvList = tpc.proxy().scanner_next_k(cookie, k);
+ for (PKeyValue kv : kvList.getResults()) {
+ assertEquals(Integer.parseInt(new String(kv.getKey().getRow())), i);
+
+ i += 2;
+ }
+ hasNext = kvList.isMore();
+ }
+ }
+
+ @Test
+ public void readWriteOneShotWithRange() throws Exception {
+ int maxInserts = 100000;
+ Map<ByteBuffer,List<PColumnUpdate>> mutations = new
HashMap<ByteBuffer,List<PColumnUpdate>>();
+ String format = "%1$05d";
+ for (int i = 0; i < maxInserts; i++) {
+ addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i,
Util.randString(10));
+
+ if (i % 1000 == 0 || i == maxInserts - 1) {
+ tpc.proxy().updateAndFlush(userpass, testtable, mutations);
+ mutations.clear();
+ }
+ }
+
+ PKey stop = new PKey();
+ stop.setRow("5".getBytes());
+ String cookie = tpc.proxy().createScanner(userpass, testtable, null, null,
new PRange(null, false, stop, false));
+
+ int i = 0;
+ boolean hasNext = true;
+
+ int k = 1000;
+ while (hasNext) {
+ PScanResult kvList = tpc.proxy().scanner_next_k(cookie, k);
+ i += kvList.getResultsSize();
+ hasNext = kvList.isMore();
+ }
+ assertEquals(i, 50000);
+ }
+
+ /**
+ * Insert 100000 cells which have as the row [0..99999] (padded with zeros).
Filter the results so only the even numbers come back.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void readWriteOneShotWithFilterIterator() throws Exception {
+ int maxInserts = 10000;
+ Map<ByteBuffer,List<PColumnUpdate>> mutations = new
HashMap<ByteBuffer,List<PColumnUpdate>>();
+ String format = "%1$05d";
+ for (int i = 0; i < maxInserts; i++) {
+ addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i,
Util.randString(10));
+
+ if (i % 1000 == 0 || i == maxInserts - 1) {
+
+ tpc.proxy().updateAndFlush(userpass, testtable, mutations);
+ mutations.clear();
+
+ }
+
+ }
+
+ String regex = ".*[02468]";
+
+ IteratorSetting is = new IteratorSetting(50, regex, RegExFilter.class);
+ RegExFilter.setRegexs(is, regex, null, null, null, false);
+
+ PIteratorSetting pis = Util.iteratorSetting2ProxyIteratorSetting(is);
+ String cookie = tpc.proxy().createScanner(userpass, testtable, null,
Collections.singletonList(pis), null);
+
+ int i = 0;
+ boolean hasNext = true;
+
+ int k = 1000;
+ while (hasNext) {
+ PScanResult kvList = tpc.proxy().scanner_next_k(cookie, k);
+ for (PKeyValue kv : kvList.getResults()) {
+ assertEquals(Integer.parseInt(new String(kv.getKey().getRow())), i);
+
+ i += 2;
+ }
+ hasNext = kvList.isMore();
+ }
+ }
+
+ // @Test
+ // This test takes kind of a long time. Enable it if you think you may have
memory issues.
+ public void manyWritesAndReads() throws Exception {
+ int maxInserts = 1000000;
+ Map<ByteBuffer,List<PColumnUpdate>> mutations = new
HashMap<ByteBuffer,List<PColumnUpdate>>();
+ String format = "%1$06d";
+ String writer = tpc.proxy().createWriter(userpass, testtable);
+ for (int i = 0; i < maxInserts; i++) {
+ addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i,
Util.randString(10));
+
+ if (i % 1000 == 0 || i == maxInserts - 1) {
+
+ tpc.proxy().writer_update(writer, mutations);
+ mutations.clear();
+
+ }
+
+ }
+
+ tpc.proxy().writer_flush(writer);
+ tpc.proxy().writer_close(writer);
+
+ String cookie = tpc.proxy().createBatchScanner(userpass, testtable, null,
null, null);
+
+ int i = 0;
+ boolean hasNext = true;
+
+ int k = 1000;
+ while (hasNext) {
+ PScanResult kvList = tpc.proxy().scanner_next_k(cookie, k);
+ for (PKeyValue kv : kvList.getResults()) {
+ assertEquals(Integer.parseInt(new String(kv.getKey().getRow())), i);
+ i++;
+ }
+ hasNext = kvList.isMore();
+ if (hasNext)
+ assertEquals(k, kvList.getResults().size());
+ }
+ assertEquals(maxInserts, i);
+ }
+
+ @Test
+ public void asynchReadWrite() throws Exception {
+ int maxInserts = 10000;
+ Map<ByteBuffer,List<PColumnUpdate>> mutations = new
HashMap<ByteBuffer,List<PColumnUpdate>>();
+ String format = "%1$05d";
+ String writer = tpc.proxy().createWriter(userpass, testtable);
+ for (int i = 0; i < maxInserts; i++) {
+ addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i,
Util.randString(10));
+
+ if (i % 1000 == 0 || i == maxInserts - 1) {
+ tpc.proxy().writer_update(writer, mutations);
+ mutations.clear();
+ }
+ }
+
+ tpc.proxy().writer_flush(writer);
+ tpc.proxy().writer_close(writer);
+
+ String regex = ".*[02468]";
+
+ IteratorSetting is = new IteratorSetting(50, regex, RegExFilter.class);
+ RegExFilter.setRegexs(is, regex, null, null, null, false);
+
+ PIteratorSetting pis = Util.iteratorSetting2ProxyIteratorSetting(is);
+ String cookie = tpc.proxy().createBatchScanner(userpass, testtable, null,
Collections.singletonList(pis), null);
+
+ int i = 0;
+ boolean hasNext = true;
+
+ int k = 1000;
+ int numRead = 0;
+ while (hasNext) {
+ PScanResult kvList = tpc.proxy().scanner_next_k(cookie, k);
+ for (PKeyValue kv : kvList.getResults()) {
+ assertEquals(i, Integer.parseInt(new String(kv.getKey().getRow())));
+ numRead++;
+ i += 2;
+ }
+ hasNext = kvList.isMore();
+ }
+ assertEquals(maxInserts / 2, numRead);
+ }
+
+ @Test
+ public void testVisibility() throws Exception {
+
+ Set<ByteBuffer> auths = new HashSet<ByteBuffer>();
+ auths.add(ByteBuffer.wrap("even".getBytes()));
+ tpc.proxy().securityOperations_changeUserAuthorizations(userpass, "root",
auths);
+
+ int maxInserts = 10000;
+ Map<ByteBuffer,List<PColumnUpdate>> mutations = new
HashMap<ByteBuffer,List<PColumnUpdate>>();
+ String format = "%1$05d";
+ String writer = tpc.proxy().createWriter(userpass, testtable);
+ for (int i = 0; i < maxInserts; i++) {
+ if (i % 2 == 0)
+ addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i,
"even", Util.randString(10));
+ else
+ addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i,
"odd", Util.randString(10));
+
+ if (i % 1000 == 0 || i == maxInserts - 1) {
+ tpc.proxy().writer_update(writer, mutations);
+ mutations.clear();
+ }
+ }
+
+ tpc.proxy().writer_flush(writer);
+ tpc.proxy().writer_close(writer);
+ String cookie = tpc.proxy().createBatchScanner(userpass, testtable, auths,
null, null);
+
+ int i = 0;
+ boolean hasNext = true;
+
+ int k = 1000;
+ int numRead = 0;
+ while (hasNext) {
+ PScanResult kvList = tpc.proxy().scanner_next_k(cookie, k);
+ for (PKeyValue kv : kvList.getResults()) {
+ assertEquals(Integer.parseInt(new String(kv.getKey().getRow())), i);
+ i += 2;
+ numRead++;
+ }
+ hasNext = kvList.isMore();
+
+ }
+ assertEquals(maxInserts / 2, numRead);
+ }
+
+}
Propchange:
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyReadWrite.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxySecurityOperations.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxySecurityOperations.java?rev=1437567&view=auto
==============================================================================
---
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxySecurityOperations.java
(added)
+++
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxySecurityOperations.java
Wed Jan 23 16:57:00 2013
@@ -0,0 +1,142 @@
+/*
+ * 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.proxy;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.ByteBuffer;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.accumulo.proxy.Proxy;
+import org.apache.accumulo.proxy.TestProxyClient;
+import org.apache.accumulo.proxy.thrift.PSystemPermission;
+import org.apache.accumulo.proxy.thrift.PTablePermission;
+import org.apache.accumulo.proxy.thrift.PTimeType;
+import org.apache.accumulo.proxy.thrift.UserPass;
+import org.apache.thrift.TException;
+import org.apache.thrift.server.TServer;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestProxySecurityOperations {
+ protected static TServer proxy;
+ protected static Thread thread;
+ protected static TestProxyClient tpc;
+ protected static UserPass userpass;
+ protected static final int port = 10196;
+ protected static final String testtable = "testtable";
+ protected static final String testuser = "VonJines";
+ protected static final ByteBuffer testpw =
ByteBuffer.wrap("fiveones".getBytes());
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ Properties prop = new Properties();
+ prop.setProperty("org.apache.accumulo.proxy.ProxyServer.useMockInstance",
"true");
+
+ proxy =
Proxy.createProxyServer(Class.forName("org.apache.accumulo.proxy.thrift.AccumuloProxy"),
+ Class.forName("org.apache.accumulo.proxy.ProxyServer"), port, prop);
+ thread = new Thread() {
+ @Override
+ public void run() {
+ proxy.serve();
+ }
+ };
+ thread.start();
+
+ tpc = new TestProxyClient("localhost", port);
+ userpass = new UserPass("root", ByteBuffer.wrap("".getBytes()));
+ }
+
+ @AfterClass
+ public static void tearDown() throws InterruptedException {
+ proxy.stop();
+ thread.join();
+ }
+
+ @Before
+ public void makeTestTableAndUser() throws Exception {
+ tpc.proxy().tableOperations_create(userpass, testtable, true,
PTimeType.MILLIS);
+ tpc.proxy().securityOperations_createUser(userpass, testuser, testpw);
+ }
+
+ @After
+ public void deleteTestTable() throws Exception {
+ tpc.proxy().tableOperations_delete(userpass, testtable);
+ tpc.proxy().securityOperations_dropUser(userpass, testuser);
+ }
+
+ @Test
+ public void create() throws TException {
+ tpc.proxy().securityOperations_createUser(userpass, testuser + "2",
testpw);
+
assertTrue(tpc.proxy().securityOperations_listUsers(userpass).contains(testuser
+ "2"));
+ tpc.proxy().securityOperations_dropUser(userpass, testuser + "2");
+
assertTrue(!tpc.proxy().securityOperations_listUsers(userpass).contains(testuser
+ "2"));
+ }
+
+ @Test
+ public void authenticate() throws TException {
+ assertTrue(tpc.proxy().securityOperations_authenticateUser(userpass,
testuser, testpw));
+ assertFalse(tpc.proxy().securityOperations_authenticateUser(userpass,
"EvilUser", testpw));
+
+ tpc.proxy().securityOperations_changeUserPassword(userpass, testuser,
ByteBuffer.wrap("newpass".getBytes()));
+ assertFalse(tpc.proxy().securityOperations_authenticateUser(userpass,
testuser, testpw));
+ assertTrue(tpc.proxy().securityOperations_authenticateUser(userpass,
testuser, ByteBuffer.wrap("newpass".getBytes())));
+
+ }
+
+ @Test
+ public void tablePermissions() throws TException {
+ tpc.proxy().securityOperations_grantTablePermission(userpass, testuser,
testtable, PTablePermission.ALTER_TABLE);
+ assertTrue(tpc.proxy().securityOperations_hasTablePermission(userpass,
testuser, testtable, PTablePermission.ALTER_TABLE));
+
+ tpc.proxy().securityOperations_revokeTablePermission(userpass, testuser,
testtable, PTablePermission.ALTER_TABLE);
+ assertFalse(tpc.proxy().securityOperations_hasTablePermission(userpass,
testuser, testtable, PTablePermission.ALTER_TABLE));
+
+ }
+
+ @Test
+ public void systemPermissions() throws TException {
+ tpc.proxy().securityOperations_grantSystemPermission(userpass, testuser,
PSystemPermission.ALTER_USER);
+ assertTrue(tpc.proxy().securityOperations_hasSystemPermission(userpass,
testuser, PSystemPermission.ALTER_USER));
+
+ tpc.proxy().securityOperations_revokeSystemPermission(userpass, testuser,
PSystemPermission.ALTER_USER);
+ assertFalse(tpc.proxy().securityOperations_hasSystemPermission(userpass,
testuser, PSystemPermission.ALTER_USER));
+
+ }
+
+ @Test
+ public void auths() throws TException {
+ HashSet<ByteBuffer> newauths = new HashSet<ByteBuffer>();
+ newauths.add(ByteBuffer.wrap("BBR".getBytes()));
+ newauths.add(ByteBuffer.wrap("Barney".getBytes()));
+ tpc.proxy().securityOperations_changeUserAuthorizations(userpass,
testuser, newauths);
+ List<ByteBuffer> actualauths =
tpc.proxy().securityOperations_getUserAuthorizations(userpass, testuser);
+ assertEquals(actualauths.size(), newauths.size());
+
+ for (ByteBuffer auth : actualauths) {
+ assertTrue(newauths.contains(auth));
+ }
+ }
+
+}
Propchange:
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxySecurityOperations.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyTableOperations.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyTableOperations.java?rev=1437567&view=auto
==============================================================================
---
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyTableOperations.java
(added)
+++
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyTableOperations.java
Wed Jan 23 16:57:00 2013
@@ -0,0 +1,216 @@
+/*
+ * 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.proxy;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.accumulo.proxy.Proxy;
+import org.apache.accumulo.proxy.TestProxyClient;
+import org.apache.accumulo.proxy.thrift.PColumnUpdate;
+import org.apache.accumulo.proxy.thrift.PTimeType;
+import org.apache.accumulo.proxy.thrift.UserPass;
+import org.apache.thrift.TException;
+import org.apache.thrift.server.TServer;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestProxyTableOperations {
+
+ protected static TServer proxy;
+ protected static Thread thread;
+ protected static TestProxyClient tpc;
+ protected static UserPass userpass;
+ protected static final int port = 10195;
+ protected static final String testtable = "testtable";
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ Properties prop = new Properties();
+ prop.setProperty("org.apache.accumulo.proxy.ProxyServer.useMockInstance",
"true");
+
+ proxy =
Proxy.createProxyServer(Class.forName("org.apache.accumulo.proxy.thrift.AccumuloProxy"),
+ Class.forName("org.apache.accumulo.proxy.ProxyServer"), port, prop);
+ thread = new Thread() {
+ @Override
+ public void run() {
+ proxy.serve();
+ }
+ };
+ thread.start();
+ tpc = new TestProxyClient("localhost", port);
+ userpass = new UserPass("root", ByteBuffer.wrap("".getBytes()));
+ }
+
+ @AfterClass
+ public static void tearDown() throws InterruptedException {
+ proxy.stop();
+ thread.join();
+ }
+
+ @Before
+ public void makeTestTable() throws Exception {
+ tpc.proxy().tableOperations_create(userpass, testtable, true,
PTimeType.MILLIS);
+ }
+
+ @After
+ public void deleteTestTable() throws Exception {
+ tpc.proxy().tableOperations_delete(userpass, testtable);
+ }
+
+ @Test
+ public void ping() throws Exception {
+ tpc.proxy().ping(userpass);
+ }
+
+ @Test
+ public void createExistsDelete() throws TException {
+ assertFalse(tpc.proxy().tableOperations_exists(userpass, "testtable2"));
+ tpc.proxy().tableOperations_create(userpass, "testtable2", true,
PTimeType.MILLIS);
+ assertTrue(tpc.proxy().tableOperations_exists(userpass, "testtable2"));
+ tpc.proxy().tableOperations_delete(userpass, "testtable2");
+ assertFalse(tpc.proxy().tableOperations_exists(userpass, "testtable2"));
+ }
+
+ @Test
+ public void listRename() throws TException {
+ assertFalse(tpc.proxy().tableOperations_exists(userpass, "testtable2"));
+ tpc.proxy().tableOperations_rename(userpass, testtable, "testtable2");
+ assertTrue(tpc.proxy().tableOperations_exists(userpass, "testtable2"));
+ tpc.proxy().tableOperations_rename(userpass, "testtable2", testtable);
+
assertTrue(tpc.proxy().tableOperations_list(userpass).contains("testtable"));
+
+ }
+
+ // This test does not yet function because the backing Mock instance does
not yet support merging
+ // TODO: add back in as a test when Mock is improved
+ // @Test
+ public void merge() throws TException {
+ Set<ByteBuffer> splits = new HashSet<ByteBuffer>();
+ splits.add(ByteBuffer.wrap("a".getBytes()));
+ splits.add(ByteBuffer.wrap("c".getBytes()));
+ splits.add(ByteBuffer.wrap("z".getBytes()));
+ tpc.proxy().tableOperations_addSplits(userpass, testtable, splits);
+
+ tpc.proxy().tableOperations_merge(userpass, testtable,
ByteBuffer.wrap("b".getBytes()), ByteBuffer.wrap("d".getBytes()));
+
+ splits.remove("c");
+
+ List<ByteBuffer> tableSplits =
tpc.proxy().tableOperations_getSplits(userpass, testtable, 10);
+
+ for (ByteBuffer split : tableSplits)
+ assertTrue(splits.contains(split));
+ assertTrue(tableSplits.size() == splits.size());
+
+ }
+
+ @Test
+ public void splits() throws TException {
+ Set<ByteBuffer> splits = new HashSet<ByteBuffer>();
+ splits.add(ByteBuffer.wrap("a".getBytes()));
+ splits.add(ByteBuffer.wrap("b".getBytes()));
+ splits.add(ByteBuffer.wrap("z".getBytes()));
+ tpc.proxy().tableOperations_addSplits(userpass, testtable, splits);
+
+ List<ByteBuffer> tableSplits =
tpc.proxy().tableOperations_getSplits(userpass, testtable, 10);
+
+ for (ByteBuffer split : tableSplits)
+ assertTrue(splits.contains(split));
+ assertTrue(tableSplits.size() == splits.size());
+ }
+
+ @Test
+ public void constraints() throws TException {
+ int cid = tpc.proxy().tableOperations_addConstraint(userpass, testtable,
"org.apache.accumulo.TestConstraint");
+ Map<String,Integer> constraints =
tpc.proxy().tableOperations_listConstraints(userpass, testtable);
+ assertEquals((int) constraints.get("org.apache.accumulo.TestConstraint"),
cid);
+ tpc.proxy().tableOperations_removeConstraint(userpass, testtable, cid);
+ constraints = tpc.proxy().tableOperations_listConstraints(userpass,
testtable);
+ assertNull(constraints.get("org.apache.accumulo.TestConstraint"));
+ }
+
+ // This test does not yet function because the backing Mock instance does
not yet support locality groups
+ // TODO: add back in as a test when Mock is improved
+ // @Test
+ public void localityGroups() throws TException {
+ Map<String,Set<String>> groups = new HashMap<String,Set<String>>();
+ Set<String> group1 = new HashSet<String>();
+ group1.add("cf1");
+ groups.put("group1", group1);
+ Set<String> group2 = new HashSet<String>();
+ group2.add("cf2");
+ group2.add("cf3");
+ groups.put("group2", group2);
+ tpc.proxy().tableOperations_setLocalityGroups(userpass, testtable, groups);
+
+ Map<String,Set<String>> actualGroups =
tpc.proxy().tableOperations_getLocalityGroups(userpass, testtable);
+
+ assertEquals(groups.size(), actualGroups.size());
+ for (String groupName : groups.keySet()) {
+ assertTrue(actualGroups.containsKey(groupName));
+ assertEquals(groups.get(groupName).size(),
actualGroups.get(groupName).size());
+ for (String cf : groups.get(groupName)) {
+ assertTrue(actualGroups.get(groupName).contains(cf));
+ }
+ }
+ }
+
+ @Test
+ public void tableProperties() throws TException {
+ tpc.proxy().tableOperations_setProperty(userpass, testtable,
"test.property1", "wharrrgarbl");
+ assertEquals(tpc.proxy().tableOperations_getProperties(userpass,
testtable).get("test.property1"), "wharrrgarbl");
+ tpc.proxy().tableOperations_removeProperty(userpass, testtable,
"test.property1");
+ assertNull(tpc.proxy().tableOperations_getProperties(userpass,
testtable).get("test.property1"));
+ }
+
+ private static void addMutation(Map<ByteBuffer,List<PColumnUpdate>>
mutations, String row, String cf, String cq, String value) {
+ PColumnUpdate update = new PColumnUpdate(ByteBuffer.wrap(cf.getBytes()),
ByteBuffer.wrap(cq.getBytes()));
+ update.setValue(value.getBytes());
+ mutations.put(ByteBuffer.wrap(row.getBytes()),
Collections.singletonList(update));
+ }
+
+ @Test
+ public void tableOperationsRowMethods() throws TException {
+ List<ByteBuffer> auths =
tpc.proxy().securityOperations_getUserAuthorizations(userpass, "root");
+ // System.out.println(auths);
+ Map<ByteBuffer,List<PColumnUpdate>> mutations = new
HashMap<ByteBuffer,List<PColumnUpdate>>();
+ for (int i = 0; i < 10; i++) {
+ addMutation(mutations, "" + i, "cf", "cq", "");
+ }
+ tpc.proxy().updateAndFlush(userpass, testtable, mutations);
+
+ assertEquals(tpc.proxy().tableOperations_getMaxRow(userpass, testtable,
auths, null, true, null, true), ByteBuffer.wrap("9".getBytes()));
+
+
tpc.proxy().tableOperations_deleteRows(userpass,testtable,ByteBuffer.wrap("51".getBytes()),
ByteBuffer.wrap("99".getBytes()));
+ assertEquals(tpc.proxy().tableOperations_getMaxRow(userpass, testtable,
auths, null, true, null, true), ByteBuffer.wrap("5".getBytes()));
+ }
+
+}
Propchange:
accumulo/trunk/proxy/src/test/java/org/apache/accumulo/proxy/TestProxyTableOperations.java
------------------------------------------------------------------------------
svn:eol-style = native