You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2010/03/29 21:15:20 UTC
svn commit: r928876 [12/13] - in /hadoop/hbase/trunk: ./ contrib/stargate/
contrib/stargate/conf/ contrib/stargate/core/ contrib/stargate/core/src/
contrib/stargate/core/src/main/ contrib/stargate/core/src/main/java/
contrib/stargate/core/src/main/java...
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/TestStatusResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/TestStatusResource.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/TestStatusResource.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/TestStatusResource.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.hadoop.hbase.stargate.client.Client;
+import org.apache.hadoop.hbase.stargate.client.Cluster;
+import org.apache.hadoop.hbase.stargate.client.Response;
+import org.apache.hadoop.hbase.stargate.model.StorageClusterStatusModel;
+import org.apache.hadoop.hbase.util.Bytes;
+
+public class TestStatusResource extends MiniClusterTestBase {
+ private static final byte[] ROOT_REGION_NAME = Bytes.toBytes("-ROOT-,,0");
+ private static final byte[] META_REGION_NAME = Bytes.toBytes(".META.,,1");
+
+ private Client client;
+ private JAXBContext context;
+
+ public TestStatusResource() throws JAXBException {
+ super();
+ context = JAXBContext.newInstance(
+ StorageClusterStatusModel.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ client = new Client(new Cluster().add("localhost", testServletPort));
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ client.shutdown();
+ super.tearDown();
+ }
+
+ private void validate(StorageClusterStatusModel model) {
+ assertNotNull(model);
+ assertTrue(model.getRegions() >= 2);
+ assertTrue(model.getRequests() >= 0);
+ // assumes minicluster with two regionservers
+ assertTrue(model.getAverageLoad() >= 1.0);
+ assertNotNull(model.getLiveNodes());
+ assertNotNull(model.getDeadNodes());
+ assertFalse(model.getLiveNodes().isEmpty());
+ boolean foundRoot = false, foundMeta = false;
+ for (StorageClusterStatusModel.Node node: model.getLiveNodes()) {
+ assertNotNull(node.getName());
+ assertTrue(node.getStartCode() > 0L);
+ assertTrue(node.getRequests() >= 0);
+ assertFalse(node.getRegions().isEmpty());
+ for (StorageClusterStatusModel.Node.Region region: node.getRegions()) {
+ if (Bytes.equals(region.getName(), ROOT_REGION_NAME)) {
+ foundRoot = true;
+ } else if (Bytes.equals(region.getName(), META_REGION_NAME)) {
+ foundMeta = true;
+ }
+ }
+ }
+ assertTrue(foundRoot);
+ assertTrue(foundMeta);
+ }
+
+ public void testGetClusterStatusXML() throws IOException, JAXBException {
+ Response response = client.get("/status/cluster", MIMETYPE_XML);
+ assertEquals(response.getCode(), 200);
+ StorageClusterStatusModel model = (StorageClusterStatusModel)
+ context.createUnmarshaller().unmarshal(
+ new ByteArrayInputStream(response.getBody()));
+ validate(model);
+ }
+
+ public void testGetClusterStatusPB() throws IOException {
+ Response response = client.get("/status/cluster", MIMETYPE_PROTOBUF);
+ assertEquals(response.getCode(), 200);
+ StorageClusterStatusModel model = new StorageClusterStatusModel();
+ model.getObjectFromMessage(response.getBody());
+ validate(model);
+ }
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/TestTableResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/TestTableResource.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/TestTableResource.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/TestTableResource.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.stargate.client.Client;
+import org.apache.hadoop.hbase.stargate.client.Cluster;
+import org.apache.hadoop.hbase.stargate.client.Response;
+import org.apache.hadoop.hbase.stargate.model.TableModel;
+import org.apache.hadoop.hbase.stargate.model.TableInfoModel;
+import org.apache.hadoop.hbase.stargate.model.TableListModel;
+import org.apache.hadoop.hbase.stargate.model.TableRegionModel;
+import org.apache.hadoop.hbase.util.Bytes;
+
+public class TestTableResource extends MiniClusterTestBase {
+ private static String TABLE = "TestTableResource";
+ private static String COLUMN = "test:";
+
+ private Client client;
+ private JAXBContext context;
+ private HBaseAdmin admin;
+
+ public TestTableResource() throws JAXBException {
+ super();
+ context = JAXBContext.newInstance(
+ TableModel.class,
+ TableInfoModel.class,
+ TableListModel.class,
+ TableRegionModel.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ client = new Client(new Cluster().add("localhost", testServletPort));
+ admin = new HBaseAdmin(conf);
+ if (admin.tableExists(TABLE)) {
+ return;
+ }
+ HTableDescriptor htd = new HTableDescriptor(TABLE);
+ htd.addFamily(new HColumnDescriptor(KeyValue.parseColumn(
+ Bytes.toBytes(COLUMN))[0]));
+ admin.createTable(htd);
+ new HTable(conf, TABLE);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ client.shutdown();
+ super.tearDown();
+ }
+
+ private void checkTableList(TableListModel model) {
+ boolean found = false;
+ Iterator<TableModel> tables = model.getTables().iterator();
+ assertTrue(tables.hasNext());
+ while (tables.hasNext()) {
+ TableModel table = tables.next();
+ if (table.getName().equals(TABLE)) {
+ found = true;
+ break;
+ }
+ }
+ assertTrue(found);
+ }
+
+ public void testTableListText() throws IOException {
+ Response response = client.get("/", MIMETYPE_PLAIN);
+ assertEquals(response.getCode(), 200);
+ }
+
+ public void testTableListXML() throws IOException, JAXBException {
+ Response response = client.get("/", MIMETYPE_XML);
+ assertEquals(response.getCode(), 200);
+ TableListModel model = (TableListModel)
+ context.createUnmarshaller()
+ .unmarshal(new ByteArrayInputStream(response.getBody()));
+ checkTableList(model);
+ }
+
+ public void testTableListJSON() throws IOException {
+ Response response = client.get("/", MIMETYPE_JSON);
+ assertEquals(response.getCode(), 200);
+ }
+
+ public void testTableListPB() throws IOException, JAXBException {
+ Response response = client.get("/", MIMETYPE_PROTOBUF);
+ assertEquals(response.getCode(), 200);
+ TableListModel model = new TableListModel();
+ model.getObjectFromMessage(response.getBody());
+ checkTableList(model);
+ }
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/TestVersionResource.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/TestVersionResource.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/TestVersionResource.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/TestVersionResource.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.stargate.client.Client;
+import org.apache.hadoop.hbase.stargate.client.Cluster;
+import org.apache.hadoop.hbase.stargate.client.Response;
+import org.apache.hadoop.hbase.stargate.model.StorageClusterVersionModel;
+import org.apache.hadoop.hbase.stargate.model.VersionModel;
+import org.apache.hadoop.hbase.util.Bytes;
+
+import com.sun.jersey.spi.container.servlet.ServletContainer;
+
+public class TestVersionResource extends MiniClusterTestBase {
+ private static final Log LOG =
+ LogFactory.getLog(TestVersionResource.class);
+
+ private Client client;
+ private JAXBContext context;
+
+ public TestVersionResource() throws JAXBException {
+ super();
+ context = JAXBContext.newInstance(
+ VersionModel.class,
+ StorageClusterVersionModel.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ client = new Client(new Cluster().add("localhost", testServletPort));
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ client.shutdown();
+ super.tearDown();
+ }
+
+ private static void validate(VersionModel model) {
+ assertNotNull(model);
+ assertNotNull(model.getStargateVersion());
+ assertEquals(model.getStargateVersion(), RESTServlet.VERSION_STRING);
+ String osVersion = model.getOsVersion();
+ assertNotNull(osVersion);
+ assertTrue(osVersion.contains(System.getProperty("os.name")));
+ assertTrue(osVersion.contains(System.getProperty("os.version")));
+ assertTrue(osVersion.contains(System.getProperty("os.arch")));
+ String jvmVersion = model.getJvmVersion();
+ assertNotNull(jvmVersion);
+ assertTrue(jvmVersion.contains(System.getProperty("java.vm.vendor")));
+ assertTrue(jvmVersion.contains(System.getProperty("java.version")));
+ assertTrue(jvmVersion.contains(System.getProperty("java.vm.version")));
+ assertNotNull(model.getServerVersion());
+ String jerseyVersion = model.getJerseyVersion();
+ assertNotNull(jerseyVersion);
+ assertEquals(jerseyVersion, ServletContainer.class.getPackage()
+ .getImplementationVersion());
+ }
+
+ public void testGetStargateVersionText() throws IOException {
+ Response response = client.get("/version", MIMETYPE_PLAIN);
+ assertTrue(response.getCode() == 200);
+ String body = Bytes.toString(response.getBody());
+ assertTrue(body.length() > 0);
+ assertTrue(body.contains(RESTServlet.VERSION_STRING));
+ assertTrue(body.contains(System.getProperty("java.vm.vendor")));
+ assertTrue(body.contains(System.getProperty("java.version")));
+ assertTrue(body.contains(System.getProperty("java.vm.version")));
+ assertTrue(body.contains(System.getProperty("os.name")));
+ assertTrue(body.contains(System.getProperty("os.version")));
+ assertTrue(body.contains(System.getProperty("os.arch")));
+ assertTrue(body.contains(ServletContainer.class.getPackage()
+ .getImplementationVersion()));
+ }
+
+ public void testGetStargateVersionXML() throws IOException, JAXBException {
+ Response response = client.get("/version", MIMETYPE_XML);
+ assertTrue(response.getCode() == 200);
+ VersionModel model = (VersionModel)
+ context.createUnmarshaller().unmarshal(
+ new ByteArrayInputStream(response.getBody()));
+ validate(model);
+ LOG.info("success retrieving Stargate version as XML");
+ }
+
+ public void testGetStargateVersionJSON() throws IOException {
+ Response response = client.get("/version", MIMETYPE_JSON);
+ assertTrue(response.getCode() == 200);
+ }
+
+ public void testGetStargateVersionPB() throws IOException {
+ Response response = client.get("/version", MIMETYPE_PROTOBUF);
+ assertTrue(response.getCode() == 200);
+ VersionModel model = new VersionModel();
+ model.getObjectFromMessage(response.getBody());
+ validate(model);
+ LOG.info("success retrieving Stargate version as protobuf");
+ }
+
+ public void testGetStorageClusterVersionText() throws IOException {
+ Response response = client.get("/version/cluster", MIMETYPE_PLAIN);
+ assertTrue(response.getCode() == 200);
+ }
+
+ public void testGetStorageClusterVersionXML() throws IOException,
+ JAXBException {
+ Response response = client.get("/version/cluster", MIMETYPE_XML);
+ assertTrue(response.getCode() == 200);
+ StorageClusterVersionModel clusterVersionModel =
+ (StorageClusterVersionModel)
+ context.createUnmarshaller().unmarshal(
+ new ByteArrayInputStream(response.getBody()));
+ assertNotNull(clusterVersionModel);
+ assertNotNull(clusterVersionModel.getVersion());
+ LOG.info("success retrieving storage cluster version as XML");
+ }
+
+ public void testGetStorageClusterVersionJSON() throws IOException {
+ Response response = client.get("/version/cluster", MIMETYPE_JSON);
+ assertTrue(response.getCode() == 200);
+ }
+
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestHBCAuthenticator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestHBCAuthenticator.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestHBCAuthenticator.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestHBCAuthenticator.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate.auth;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.stargate.User;
+
+import junit.framework.TestCase;
+
+public class TestHBCAuthenticator extends TestCase {
+
+ static final String UNKNOWN_TOKEN = "00000000000000000000000000000000";
+ static final String ADMIN_TOKEN = "e998efffc67c49c6e14921229a51b7b3";
+ static final String ADMIN_USERNAME = "testAdmin";
+ static final String USER_TOKEN = "da4829144e3a2febd909a6e1b4ed7cfa";
+ static final String USER_USERNAME = "testUser";
+ static final String DISABLED_TOKEN = "17de5b5db0fd3de0847bd95396f36d92";
+ static final String DISABLED_USERNAME = "disabledUser";
+
+ static Configuration conf;
+ static HBCAuthenticator authenticator;
+ static {
+ conf = HBaseConfiguration.create();
+ conf.set("stargate.auth.token." + USER_TOKEN, USER_USERNAME);
+ conf.set("stargate.auth.user." + USER_USERNAME + ".admin", "false");
+ conf.set("stargate.auth.user." + USER_USERNAME + ".disabled", "false");
+ conf.set("stargate.auth.token." + ADMIN_TOKEN, ADMIN_USERNAME);
+ conf.set("stargate.auth.user." + ADMIN_USERNAME + ".admin", "true");
+ conf.set("stargate.auth.user." + ADMIN_USERNAME + ".disabled", "false");
+ conf.set("stargate.auth.token." + DISABLED_TOKEN, DISABLED_USERNAME);
+ conf.set("stargate.auth.user." + DISABLED_USERNAME + ".admin", "false");
+ conf.set("stargate.auth.user." + DISABLED_USERNAME + ".disabled", "true");
+ authenticator = new HBCAuthenticator(conf);
+ }
+
+ public void testGetUserUnknown() throws Exception {
+ User user = authenticator.getUserForToken(UNKNOWN_TOKEN);
+ assertNull(user);
+ }
+
+ public void testGetAdminUser() throws Exception {
+ User user = authenticator.getUserForToken(ADMIN_TOKEN);
+ assertNotNull(user);
+ assertEquals(user.getName(), ADMIN_USERNAME);
+ assertTrue(user.isAdmin());
+ assertFalse(user.isDisabled());
+ }
+
+ public void testGetPlainUser() throws Exception {
+ User user = authenticator.getUserForToken(USER_TOKEN);
+ assertNotNull(user);
+ assertEquals(user.getName(), USER_USERNAME);
+ assertFalse(user.isAdmin());
+ assertFalse(user.isDisabled());
+ }
+
+ public void testGetDisabledUser() throws Exception {
+ User user = authenticator.getUserForToken(DISABLED_TOKEN);
+ assertNotNull(user);
+ assertEquals(user.getName(), DISABLED_USERNAME);
+ assertFalse(user.isAdmin());
+ assertTrue(user.isDisabled());
+ }
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestHTableAuthenticator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestHTableAuthenticator.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestHTableAuthenticator.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestHTableAuthenticator.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate.auth;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.stargate.MiniClusterTestBase;
+import org.apache.hadoop.hbase.stargate.User;
+import org.apache.hadoop.hbase.util.Bytes;
+
+public class TestHTableAuthenticator extends MiniClusterTestBase {
+
+ static final String UNKNOWN_TOKEN = "00000000000000000000000000000000";
+ static final String ADMIN_TOKEN = "e998efffc67c49c6e14921229a51b7b3";
+ static final String ADMIN_USERNAME = "testAdmin";
+ static final String USER_TOKEN = "da4829144e3a2febd909a6e1b4ed7cfa";
+ static final String USER_USERNAME = "testUser";
+ static final String DISABLED_TOKEN = "17de5b5db0fd3de0847bd95396f36d92";
+ static final String DISABLED_USERNAME = "disabledUser";
+
+ static final String TABLE = "TestHTableAuthenticator";
+ static final byte[] USER = Bytes.toBytes("user");
+ static final byte[] NAME = Bytes.toBytes("name");
+ static final byte[] ADMIN = Bytes.toBytes("admin");
+ static final byte[] DISABLED = Bytes.toBytes("disabled");
+
+ HTableAuthenticator authenticator;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ HBaseAdmin admin = new HBaseAdmin(conf);
+ if (!admin.tableExists(TABLE)) {
+ HTableDescriptor htd = new HTableDescriptor(TABLE);
+ htd.addFamily(new HColumnDescriptor(USER));
+ admin.createTable(htd);
+ HTable table = new HTable(conf, TABLE);
+ Put put = new Put(Bytes.toBytes(ADMIN_TOKEN));
+ put.add(USER, NAME, Bytes.toBytes(ADMIN_USERNAME));
+ put.add(USER, ADMIN, Bytes.toBytes(true));
+ table.put(put);
+ put = new Put(Bytes.toBytes(USER_TOKEN));
+ put.add(USER, NAME, Bytes.toBytes(USER_USERNAME));
+ put.add(USER, ADMIN, Bytes.toBytes(false));
+ table.put(put);
+ put = new Put(Bytes.toBytes(DISABLED_TOKEN));
+ put.add(USER, NAME, Bytes.toBytes(DISABLED_USERNAME));
+ put.add(USER, DISABLED, Bytes.toBytes(true));
+ table.put(put);
+ table.flushCommits();
+ }
+ authenticator = new HTableAuthenticator(conf, TABLE);
+ }
+
+ public void testGetUserUnknown() throws Exception {
+ User user = authenticator.getUserForToken(UNKNOWN_TOKEN);
+ assertNull(user);
+ }
+
+ public void testGetAdminUser() throws Exception {
+ User user = authenticator.getUserForToken(ADMIN_TOKEN);
+ assertNotNull(user);
+ assertEquals(user.getName(), ADMIN_USERNAME);
+ assertTrue(user.isAdmin());
+ assertFalse(user.isDisabled());
+ }
+
+ public void testGetPlainUser() throws Exception {
+ User user = authenticator.getUserForToken(USER_TOKEN);
+ assertNotNull(user);
+ assertEquals(user.getName(), USER_USERNAME);
+ assertFalse(user.isAdmin());
+ assertFalse(user.isDisabled());
+ }
+
+ public void testGetDisabledUser() throws Exception {
+ User user = authenticator.getUserForToken(DISABLED_TOKEN);
+ assertNotNull(user);
+ assertEquals(user.getName(), DISABLED_USERNAME);
+ assertFalse(user.isAdmin());
+ assertTrue(user.isDisabled());
+ }
+
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestJDBCAuthenticator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestJDBCAuthenticator.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestJDBCAuthenticator.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestJDBCAuthenticator.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate.auth;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.hadoop.hbase.stargate.User;
+import org.apache.hadoop.util.StringUtils;
+
+import junit.framework.TestCase;
+
+public class TestJDBCAuthenticator extends TestCase {
+
+ static final Log LOG = LogFactory.getLog(TestJDBCAuthenticator.class);
+
+ static final String TABLE = "users";
+ static final String JDBC_URL = "jdbc:hsqldb:mem:test";
+
+ static final String UNKNOWN_TOKEN = "00000000000000000000000000000000";
+ static final String ADMIN_TOKEN = "e998efffc67c49c6e14921229a51b7b3";
+ static final String ADMIN_USERNAME = "testAdmin";
+ static final String USER_TOKEN = "da4829144e3a2febd909a6e1b4ed7cfa";
+ static final String USER_USERNAME = "testUser";
+ static final String DISABLED_TOKEN = "17de5b5db0fd3de0847bd95396f36d92";
+ static final String DISABLED_USERNAME = "disabledUser";
+
+ static JDBCAuthenticator authenticator;
+ static {
+ try {
+ Class.forName("org.hsqldb.jdbcDriver");
+ Connection c = DriverManager.getConnection(JDBC_URL, "SA", "");
+ c.createStatement().execute(
+ "CREATE TABLE " + TABLE + " ( " +
+ "token CHAR(32) PRIMARY KEY, " +
+ "name VARCHAR(32), " +
+ "admin BOOLEAN, " +
+ "disabled BOOLEAN " +
+ ")");
+ c.createStatement().execute(
+ "INSERT INTO " + TABLE + " ( token,name,admin,disabled ) " +
+ "VALUES ( '" + ADMIN_TOKEN + "','" + ADMIN_USERNAME +
+ "',TRUE,FALSE )");
+ c.createStatement().execute(
+ "INSERT INTO " + TABLE + " ( token,name,admin,disabled ) " +
+ "VALUES ( '" + USER_TOKEN + "','" + USER_USERNAME +
+ "',FALSE,FALSE )");
+ c.createStatement().execute(
+ "INSERT INTO " + TABLE + " ( token,name,admin,disabled ) " +
+ "VALUES ( '" + DISABLED_TOKEN + "','" + DISABLED_USERNAME +
+ "',FALSE,TRUE )");
+ c.createStatement().execute("CREATE USER test PASSWORD access");
+ c.createStatement().execute("GRANT ALL ON " + TABLE + " TO test");
+ c.close();
+ authenticator = new JDBCAuthenticator(JDBC_URL, TABLE, "test",
+ "access");
+ } catch (Exception e) {
+ LOG.warn(StringUtils.stringifyException(e));
+ }
+ }
+
+ public void testGetUserUnknown() throws Exception {
+ User user = authenticator.getUserForToken(UNKNOWN_TOKEN);
+ assertNull(user);
+ }
+
+ public void testGetAdminUser() throws Exception {
+ User user = authenticator.getUserForToken(ADMIN_TOKEN);
+ assertNotNull(user);
+ assertEquals(user.getName(), ADMIN_USERNAME);
+ assertTrue(user.isAdmin());
+ assertFalse(user.isDisabled());
+ }
+
+ public void testGetPlainUser() throws Exception {
+ User user = authenticator.getUserForToken(USER_TOKEN);
+ assertNotNull(user);
+ assertEquals(user.getName(), USER_USERNAME);
+ assertFalse(user.isAdmin());
+ assertFalse(user.isDisabled());
+ }
+
+ public void testGetDisabledUser() throws Exception {
+ User user = authenticator.getUserForToken(DISABLED_TOKEN);
+ assertNotNull(user);
+ assertEquals(user.getName(), DISABLED_USERNAME);
+ assertFalse(user.isAdmin());
+ assertTrue(user.isDisabled());
+ }
+
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestZooKeeperAuthenticator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestZooKeeperAuthenticator.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestZooKeeperAuthenticator.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/auth/TestZooKeeperAuthenticator.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate.auth;
+
+import org.apache.hadoop.hbase.stargate.MiniClusterTestBase;
+import org.apache.hadoop.hbase.stargate.User;
+import org.apache.hadoop.hbase.util.Bytes;
+
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.ZooDefs.Ids;
+
+import org.json.JSONStringer;
+
+public class TestZooKeeperAuthenticator extends MiniClusterTestBase {
+
+ static final String UNKNOWN_TOKEN = "00000000000000000000000000000000";
+ static final String ADMIN_TOKEN = "e998efffc67c49c6e14921229a51b7b3";
+ static final String ADMIN_USERNAME = "testAdmin";
+ static final String USER_TOKEN = "da4829144e3a2febd909a6e1b4ed7cfa";
+ static final String USER_USERNAME = "testUser";
+ static final String DISABLED_TOKEN = "17de5b5db0fd3de0847bd95396f36d92";
+ static final String DISABLED_USERNAME = "disabledUser";
+
+ ZooKeeperAuthenticator authenticator;
+
+ @Override
+ public void setUp() throws Exception {
+ authenticator = new ZooKeeperAuthenticator(conf);
+ ZooKeeper zk = authenticator.wrapper.getZooKeeper();
+ if (zk.exists(ZooKeeperAuthenticator.USERS_ZNODE_ROOT + "/" +
+ ADMIN_TOKEN, null) == null) {
+ zk.create(ZooKeeperAuthenticator.USERS_ZNODE_ROOT + "/" + ADMIN_TOKEN,
+ Bytes.toBytes(new JSONStringer()
+ .object()
+ .key("name").value(ADMIN_USERNAME)
+ .key("admin").value(true)
+ .endObject().toString()),
+ Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+ }
+ if (zk.exists(ZooKeeperAuthenticator.USERS_ZNODE_ROOT + "/" +
+ USER_TOKEN, null) == null) {
+ zk.create(ZooKeeperAuthenticator.USERS_ZNODE_ROOT + "/" + USER_TOKEN,
+ Bytes.toBytes(new JSONStringer()
+ .object()
+ .key("name").value(USER_USERNAME)
+ .key("disabled").value(false)
+ .endObject().toString()),
+ Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+ }
+ if (zk.exists(ZooKeeperAuthenticator.USERS_ZNODE_ROOT + "/" +
+ DISABLED_TOKEN, null) == null) {
+ zk.create(ZooKeeperAuthenticator.USERS_ZNODE_ROOT + "/" +DISABLED_TOKEN,
+ Bytes.toBytes(new JSONStringer()
+ .object()
+ .key("name").value(DISABLED_USERNAME)
+ .key("admin").value(false)
+ .key("disabled").value(true)
+ .endObject().toString()),
+ Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+ }
+ }
+
+ public void testGetUserUnknown() throws Exception {
+ User user = authenticator.getUserForToken(UNKNOWN_TOKEN);
+ assertNull(user);
+ }
+
+ public void testGetAdminUser() throws Exception {
+ User user = authenticator.getUserForToken(ADMIN_TOKEN);
+ assertNotNull(user);
+ assertEquals(user.getName(), ADMIN_USERNAME);
+ assertTrue(user.isAdmin());
+ assertFalse(user.isDisabled());
+ }
+
+ public void testGetPlainUser() throws Exception {
+ User user = authenticator.getUserForToken(USER_TOKEN);
+ assertNotNull(user);
+ assertEquals(user.getName(), USER_USERNAME);
+ assertFalse(user.isAdmin());
+ assertFalse(user.isDisabled());
+ }
+
+ public void testGetDisabledUser() throws Exception {
+ User user = authenticator.getUserForToken(DISABLED_TOKEN);
+ assertNotNull(user);
+ assertEquals(user.getName(), DISABLED_USERNAME);
+ assertFalse(user.isAdmin());
+ assertTrue(user.isDisabled());
+ }
+
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestCellModel.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestCellModel.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestCellModel.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestCellModel.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate.model;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.hadoop.hbase.util.Base64;
+import org.apache.hadoop.hbase.util.Bytes;
+
+import junit.framework.TestCase;
+
+public class TestCellModel extends TestCase {
+
+ private static final long TIMESTAMP = 1245219839331L;
+ private static final byte[] COLUMN = Bytes.toBytes("testcolumn");
+ private static final byte[] VALUE = Bytes.toBytes("testvalue");
+
+ private static final String AS_XML =
+ "<Cell timestamp=\"1245219839331\"" +
+ " column=\"dGVzdGNvbHVtbg==\">" +
+ "dGVzdHZhbHVl</Cell>";
+
+ private static final String AS_PB =
+ "Egp0ZXN0Y29sdW1uGOO6i+eeJCIJdGVzdHZhbHVl";
+
+ private JAXBContext context;
+
+ public TestCellModel() throws JAXBException {
+ super();
+ context = JAXBContext.newInstance(CellModel.class);
+ }
+
+ private CellModel buildTestModel() {
+ CellModel model = new CellModel();
+ model.setColumn(COLUMN);
+ model.setTimestamp(TIMESTAMP);
+ model.setValue(VALUE);
+ return model;
+ }
+
+ @SuppressWarnings("unused")
+ private String toXML(CellModel model) throws JAXBException {
+ StringWriter writer = new StringWriter();
+ context.createMarshaller().marshal(model, writer);
+ return writer.toString();
+ }
+
+ private CellModel fromXML(String xml) throws JAXBException {
+ return (CellModel)
+ context.createUnmarshaller().unmarshal(new StringReader(xml));
+ }
+
+ @SuppressWarnings("unused")
+ private byte[] toPB(CellModel model) {
+ return model.createProtobufOutput();
+ }
+
+ private CellModel fromPB(String pb) throws IOException {
+ return (CellModel)
+ new CellModel().getObjectFromMessage(Base64.decode(AS_PB));
+ }
+
+ private void checkModel(CellModel model) {
+ assertTrue(Bytes.equals(model.getColumn(), COLUMN));
+ assertTrue(Bytes.equals(model.getValue(), VALUE));
+ assertTrue(model.hasUserTimestamp());
+ assertEquals(model.getTimestamp(), TIMESTAMP);
+ }
+
+ public void testBuildModel() throws Exception {
+ checkModel(buildTestModel());
+ }
+
+ public void testFromXML() throws Exception {
+ checkModel(fromXML(AS_XML));
+ }
+
+ public void testFromPB() throws Exception {
+ checkModel(fromPB(AS_PB));
+ }
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestCellSetModel.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestCellSetModel.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestCellSetModel.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestCellSetModel.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate.model;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Iterator;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.hadoop.hbase.util.Base64;
+import org.apache.hadoop.hbase.util.Bytes;
+
+import junit.framework.TestCase;
+
+public class TestCellSetModel extends TestCase {
+
+ private static final byte[] ROW1 = Bytes.toBytes("testrow1");
+ private static final byte[] COLUMN1 = Bytes.toBytes("testcolumn1");
+ private static final byte[] VALUE1 = Bytes.toBytes("testvalue1");
+ private static final long TIMESTAMP1 = 1245219839331L;
+ private static final byte[] ROW2 = Bytes.toBytes("testrow1");
+ private static final byte[] COLUMN2 = Bytes.toBytes("testcolumn2");
+ private static final byte[] VALUE2 = Bytes.toBytes("testvalue2");
+ private static final long TIMESTAMP2 = 1245239813319L;
+ private static final byte[] COLUMN3 = Bytes.toBytes("testcolumn3");
+ private static final byte[] VALUE3 = Bytes.toBytes("testvalue3");
+ private static final long TIMESTAMP3 = 1245393318192L;
+
+ private static final String AS_XML =
+ "<CellSet>" +
+ "<Row key=\"dGVzdHJvdzE=\">" +
+ "<Cell timestamp=\"1245219839331\" column=\"dGVzdGNvbHVtbjE=\">" +
+ "dGVzdHZhbHVlMQ==</Cell>" +
+ "</Row>" +
+ "<Row key=\"dGVzdHJvdzE=\">" +
+ "<Cell timestamp=\"1245239813319\" column=\"dGVzdGNvbHVtbjI=\">" +
+ "dGVzdHZhbHVlMg==</Cell>" +
+ "<Cell timestamp=\"1245393318192\" column=\"dGVzdGNvbHVtbjM=\">" +
+ "dGVzdHZhbHVlMw==</Cell>" +
+ "</Row>" +
+ "</CellSet>";
+
+ private static final String AS_PB =
+ "CiwKCHRlc3Ryb3cxEiASC3Rlc3Rjb2x1bW4xGOO6i+eeJCIKdGVzdHZhbHVlMQpOCgh0ZXN0cm93" +
+ "MRIgEgt0ZXN0Y29sdW1uMhjHyc7wniQiCnRlc3R2YWx1ZTISIBILdGVzdGNvbHVtbjMYsOLnuZ8k" +
+ "Igp0ZXN0dmFsdWUz";
+
+ private JAXBContext context;
+
+ public TestCellSetModel() throws JAXBException {
+ super();
+ context = JAXBContext.newInstance(
+ CellModel.class,
+ CellSetModel.class,
+ RowModel.class);
+ }
+
+ private CellSetModel buildTestModel() {
+ CellSetModel model = new CellSetModel();
+ RowModel row;
+ row = new RowModel();
+ row.setKey(ROW1);
+ row.addCell(new CellModel(COLUMN1, TIMESTAMP1, VALUE1));
+ model.addRow(row);
+ row = new RowModel();
+ row.setKey(ROW2);
+ row.addCell(new CellModel(COLUMN2, TIMESTAMP2, VALUE2));
+ row.addCell(new CellModel(COLUMN3, TIMESTAMP3, VALUE3));
+ model.addRow(row);
+ return model;
+ }
+
+ @SuppressWarnings("unused")
+ private String toXML(CellSetModel model) throws JAXBException {
+ StringWriter writer = new StringWriter();
+ context.createMarshaller().marshal(model, writer);
+ return writer.toString();
+ }
+
+ private CellSetModel fromXML(String xml) throws JAXBException {
+ return (CellSetModel)
+ context.createUnmarshaller().unmarshal(new StringReader(xml));
+ }
+
+ @SuppressWarnings("unused")
+ private byte[] toPB(CellSetModel model) {
+ return model.createProtobufOutput();
+ }
+
+ private CellSetModel fromPB(String pb) throws IOException {
+ return (CellSetModel)
+ new CellSetModel().getObjectFromMessage(Base64.decode(AS_PB));
+ }
+
+ private void checkModel(CellSetModel model) {
+ Iterator<RowModel> rows = model.getRows().iterator();
+ RowModel row = rows.next();
+ assertTrue(Bytes.equals(ROW1, row.getKey()));
+ Iterator<CellModel> cells = row.getCells().iterator();
+ CellModel cell = cells.next();
+ assertTrue(Bytes.equals(COLUMN1, cell.getColumn()));
+ assertTrue(Bytes.equals(VALUE1, cell.getValue()));
+ assertTrue(cell.hasUserTimestamp());
+ assertEquals(cell.getTimestamp(), TIMESTAMP1);
+ assertFalse(cells.hasNext());
+ row = rows.next();
+ assertTrue(Bytes.equals(ROW2, row.getKey()));
+ cells = row.getCells().iterator();
+ cell = cells.next();
+ assertTrue(Bytes.equals(COLUMN2, cell.getColumn()));
+ assertTrue(Bytes.equals(VALUE2, cell.getValue()));
+ assertTrue(cell.hasUserTimestamp());
+ assertEquals(cell.getTimestamp(), TIMESTAMP2);
+ cell = cells.next();
+ assertTrue(Bytes.equals(COLUMN3, cell.getColumn()));
+ assertTrue(Bytes.equals(VALUE3, cell.getValue()));
+ assertTrue(cell.hasUserTimestamp());
+ assertEquals(cell.getTimestamp(), TIMESTAMP3);
+ assertFalse(cells.hasNext());
+ }
+
+ public void testBuildModel() throws Exception {
+ checkModel(buildTestModel());
+ }
+
+ public void testFromXML() throws Exception {
+ checkModel(fromXML(AS_XML));
+ }
+
+ public void testFromPB() throws Exception {
+ checkModel(fromPB(AS_PB));
+ }
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestColumnSchemaModel.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestColumnSchemaModel.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestColumnSchemaModel.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestColumnSchemaModel.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate.model;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import junit.framework.TestCase;
+
+public class TestColumnSchemaModel extends TestCase {
+
+ protected static final String COLUMN_NAME = "testcolumn";
+ protected static final boolean BLOCKCACHE = true;
+ protected static final int BLOCKSIZE = 16384;
+ protected static final boolean BLOOMFILTER = false;
+ protected static final String COMPRESSION = "GZ";
+ protected static final boolean IN_MEMORY = false;
+ protected static final int TTL = 86400;
+ protected static final int VERSIONS = 1;
+
+ protected static final String AS_XML =
+ "<ColumnSchema name=\"testcolumn\"" +
+ " BLOCKSIZE=\"16384\"" +
+ " BLOOMFILTER=\"false\"" +
+ " BLOCKCACHE=\"true\"" +
+ " COMPRESSION=\"GZ\"" +
+ " VERSIONS=\"1\"" +
+ " TTL=\"86400\"" +
+ " IN_MEMORY=\"false\"/>";
+
+ private JAXBContext context;
+
+ public TestColumnSchemaModel() throws JAXBException {
+ super();
+ context = JAXBContext.newInstance(ColumnSchemaModel.class);
+ }
+
+ protected static ColumnSchemaModel buildTestModel() {
+ ColumnSchemaModel model = new ColumnSchemaModel();
+ model.setName(COLUMN_NAME);
+ model.__setBlockcache(BLOCKCACHE);
+ model.__setBlocksize(BLOCKSIZE);
+ model.__setBloomfilter(BLOOMFILTER);
+ model.__setCompression(COMPRESSION);
+ model.__setInMemory(IN_MEMORY);
+ model.__setTTL(TTL);
+ model.__setVersions(VERSIONS);
+ return model;
+ }
+
+ @SuppressWarnings("unused")
+ private String toXML(ColumnSchemaModel model) throws JAXBException {
+ StringWriter writer = new StringWriter();
+ context.createMarshaller().marshal(model, writer);
+ return writer.toString();
+ }
+
+ private ColumnSchemaModel fromXML(String xml) throws JAXBException {
+ return (ColumnSchemaModel)
+ context.createUnmarshaller().unmarshal(new StringReader(xml));
+ }
+
+ protected static void checkModel(ColumnSchemaModel model) {
+ assertEquals(model.getName(), COLUMN_NAME);
+ assertEquals(model.__getBlockcache(), BLOCKCACHE);
+ assertEquals(model.__getBlocksize(), BLOCKSIZE);
+ assertEquals(model.__getBloomfilter(), BLOOMFILTER);
+ assertTrue(model.__getCompression().equalsIgnoreCase(COMPRESSION));
+ assertEquals(model.__getInMemory(), IN_MEMORY);
+ assertEquals(model.__getTTL(), TTL);
+ assertEquals(model.__getVersions(), VERSIONS);
+ }
+
+ public void testBuildModel() throws Exception {
+ checkModel(buildTestModel());
+ }
+
+ public void testFromXML() throws Exception {
+ checkModel(fromXML(AS_XML));
+ }
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestRowModel.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestRowModel.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestRowModel.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestRowModel.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate.model;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Iterator;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.hadoop.hbase.util.Bytes;
+
+import junit.framework.TestCase;
+
+public class TestRowModel extends TestCase {
+
+ private static final byte[] ROW1 = Bytes.toBytes("testrow1");
+ private static final byte[] COLUMN1 = Bytes.toBytes("testcolumn1");
+ private static final byte[] VALUE1 = Bytes.toBytes("testvalue1");
+ private static final long TIMESTAMP1 = 1245219839331L;
+
+ private static final String AS_XML =
+ "<Row key=\"dGVzdHJvdzE=\">" +
+ "<Cell timestamp=\"1245219839331\" column=\"dGVzdGNvbHVtbjE=\">" +
+ "dGVzdHZhbHVlMQ==</Cell>" +
+ "</Row>";
+
+ private JAXBContext context;
+
+ public TestRowModel() throws JAXBException {
+ super();
+ context = JAXBContext.newInstance(
+ CellModel.class,
+ RowModel.class);
+ }
+
+ private RowModel buildTestModel() {
+ RowModel model = new RowModel();
+ model.setKey(ROW1);
+ model.addCell(new CellModel(COLUMN1, TIMESTAMP1, VALUE1));
+ return model;
+ }
+
+ @SuppressWarnings("unused")
+ private String toXML(RowModel model) throws JAXBException {
+ StringWriter writer = new StringWriter();
+ context.createMarshaller().marshal(model, writer);
+ return writer.toString();
+ }
+
+ private RowModel fromXML(String xml) throws JAXBException {
+ return (RowModel)
+ context.createUnmarshaller().unmarshal(new StringReader(xml));
+ }
+
+ private void checkModel(RowModel model) {
+ assertTrue(Bytes.equals(ROW1, model.getKey()));
+ Iterator<CellModel> cells = model.getCells().iterator();
+ CellModel cell = cells.next();
+ assertTrue(Bytes.equals(COLUMN1, cell.getColumn()));
+ assertTrue(Bytes.equals(VALUE1, cell.getValue()));
+ assertTrue(cell.hasUserTimestamp());
+ assertEquals(cell.getTimestamp(), TIMESTAMP1);
+ assertFalse(cells.hasNext());
+ }
+
+ public void testBuildModel() throws Exception {
+ checkModel(buildTestModel());
+ }
+
+ public void testFromXML() throws Exception {
+ checkModel(fromXML(AS_XML));
+ }
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestScannerModel.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestScannerModel.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestScannerModel.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestScannerModel.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate.model;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.hadoop.hbase.util.Base64;
+import org.apache.hadoop.hbase.util.Bytes;
+
+import junit.framework.TestCase;
+
+public class TestScannerModel extends TestCase {
+ private static final byte[] START_ROW = Bytes.toBytes("abracadabra");
+ private static final byte[] END_ROW = Bytes.toBytes("zzyzx");
+ private static final byte[] COLUMN1 = Bytes.toBytes("column1");
+ private static final byte[] COLUMN2 = Bytes.toBytes("column2:foo");
+ private static final long START_TIME = 1245219839331L;
+ private static final long END_TIME = 1245393318192L;
+ private static final int BATCH = 100;
+
+ private static final String AS_XML =
+ "<Scanner startTime=\"1245219839331\"" +
+ " startRow=\"YWJyYWNhZGFicmE=\"" +
+ " endTime=\"1245393318192\"" +
+ " endRow=\"enp5eng=\"" +
+ " batch=\"100\">" +
+ "<column>Y29sdW1uMQ==</column>" +
+ "<column>Y29sdW1uMjpmb28=</column>" +
+ "</Scanner>";
+
+ private static final String AS_PB =
+ "CgthYnJhY2FkYWJyYRIFenp5engaB2NvbHVtbjEaC2NvbHVtbjI6Zm9vIGQo47qL554kMLDi57mf" +
+ "JA==";
+
+ private JAXBContext context;
+
+ public TestScannerModel() throws JAXBException {
+ super();
+ context = JAXBContext.newInstance(ScannerModel.class);
+ }
+
+ private ScannerModel buildTestModel() {
+ ScannerModel model = new ScannerModel();
+ model.setStartRow(START_ROW);
+ model.setEndRow(END_ROW);
+ model.addColumn(COLUMN1);
+ model.addColumn(COLUMN2);
+ model.setStartTime(START_TIME);
+ model.setEndTime(END_TIME);
+ model.setBatch(BATCH);
+ return model;
+ }
+
+ @SuppressWarnings("unused")
+ private String toXML(ScannerModel model) throws JAXBException {
+ StringWriter writer = new StringWriter();
+ context.createMarshaller().marshal(model, writer);
+ return writer.toString();
+ }
+
+ private ScannerModel fromXML(String xml) throws JAXBException {
+ return (ScannerModel)
+ context.createUnmarshaller().unmarshal(new StringReader(xml));
+ }
+
+ @SuppressWarnings("unused")
+ private byte[] toPB(ScannerModel model) {
+ return model.createProtobufOutput();
+ }
+
+ private ScannerModel fromPB(String pb) throws IOException {
+ return (ScannerModel)
+ new ScannerModel().getObjectFromMessage(Base64.decode(AS_PB));
+ }
+
+ private void checkModel(ScannerModel model) {
+ assertTrue(Bytes.equals(model.getStartRow(), START_ROW));
+ assertTrue(Bytes.equals(model.getEndRow(), END_ROW));
+ boolean foundCol1 = false, foundCol2 = false;
+ for (byte[] column: model.getColumns()) {
+ if (Bytes.equals(column, COLUMN1)) {
+ foundCol1 = true;
+ } else if (Bytes.equals(column, COLUMN2)) {
+ foundCol2 = true;
+ }
+ }
+ assertTrue(foundCol1);
+ assertTrue(foundCol2);
+ assertEquals(model.getStartTime(), START_TIME);
+ assertEquals(model.getEndTime(), END_TIME);
+ assertEquals(model.getBatch(), BATCH);
+ }
+
+ public void testBuildModel() throws Exception {
+ checkModel(buildTestModel());
+ }
+
+ public void testFromXML() throws Exception {
+ checkModel(fromXML(AS_XML));
+ }
+
+ public void testFromPB() throws Exception {
+ checkModel(fromPB(AS_PB));
+ }
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestStorageClusterStatusModel.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestStorageClusterStatusModel.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestStorageClusterStatusModel.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestStorageClusterStatusModel.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate.model;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Iterator;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.hadoop.hbase.util.Base64;
+import org.apache.hadoop.hbase.util.Bytes;
+
+import junit.framework.TestCase;
+
+public class TestStorageClusterStatusModel extends TestCase {
+
+ private static final String AS_XML =
+ "<ClusterStatus requests=\"0\" regions=\"2\" averageLoad=\"1.0\">" +
+ "<DeadNodes/>" +
+ "<LiveNodes><Node startCode=\"1245219839331\" requests=\"0\"" +
+ " name=\"test1\" maxHeapSizeMB=\"1024\" heapSizeMB=\"128\">" +
+ "<Region stores=\"1\" storefiles=\"1\" storefileSizeMB=\"0\"" +
+ " storefileIndexSizeMB=\"0\" name=\"LVJPT1QtLCww\"" +
+ " memstoreSizeMB=\"0\"/></Node>" +
+ "<Node startCode=\"1245239331198\" requests=\"0\" name=\"test2\"" +
+ " maxHeapSizeMB=\"1024\" heapSizeMB=\"512\">" +
+ "<Region stores=\"1\" storefiles=\"1\" storefileSizeMB=\"0\"" +
+ " storefileIndexSizeMB=\"0\" name=\"Lk1FVEEuLCwxMjQ2MDAwMDQzNzI0\"" +
+ " memstoreSizeMB=\"0\"/></Node>"+
+ "</LiveNodes></ClusterStatus>";
+
+ private static final String AS_PB =
+"Ci0KBXRlc3QxEOO6i+eeJBgAIIABKIAIMhUKCS1ST09ULSwsMBABGAEgACgAMAAKOQoFdGVzdDIQ"+
+"/pKx8J4kGAAggAQogAgyIQoVLk1FVEEuLCwxMjQ2MDAwMDQzNzI0EAEYASAAKAAwABgCIAApAAAA"+
+"AAAA8D8=";
+
+ private JAXBContext context;
+
+ public TestStorageClusterStatusModel() throws JAXBException {
+ super();
+ context = JAXBContext.newInstance(StorageClusterStatusModel.class);
+ }
+
+ private StorageClusterStatusModel buildTestModel() {
+ StorageClusterStatusModel model = new StorageClusterStatusModel();
+ model.setRegions(2);
+ model.setRequests(0);
+ model.setAverageLoad(1.0);
+ model.addLiveNode("test1", 1245219839331L, 128, 1024)
+ .addRegion(Bytes.toBytes("-ROOT-,,0"), 1, 1, 0, 0, 0);
+ model.addLiveNode("test2", 1245239331198L, 512, 1024)
+ .addRegion(Bytes.toBytes(".META.,,1246000043724"),1, 1, 0, 0, 0);
+ return model;
+ }
+
+ @SuppressWarnings("unused")
+ private String toXML(StorageClusterStatusModel model) throws JAXBException {
+ StringWriter writer = new StringWriter();
+ context.createMarshaller().marshal(model, writer);
+ return writer.toString();
+ }
+
+ private StorageClusterStatusModel fromXML(String xml) throws JAXBException {
+ return (StorageClusterStatusModel)
+ context.createUnmarshaller().unmarshal(new StringReader(xml));
+ }
+
+ @SuppressWarnings("unused")
+ private byte[] toPB(StorageClusterStatusModel model) {
+ return model.createProtobufOutput();
+ }
+
+ private StorageClusterStatusModel fromPB(String pb) throws IOException {
+ return (StorageClusterStatusModel)
+ new StorageClusterStatusModel().getObjectFromMessage(Base64.decode(AS_PB));
+ }
+
+ private void checkModel(StorageClusterStatusModel model) {
+ assertEquals(model.getRegions(), 2);
+ assertEquals(model.getRequests(), 0);
+ assertEquals(model.getAverageLoad(), 1.0);
+ Iterator<StorageClusterStatusModel.Node> nodes =
+ model.getLiveNodes().iterator();
+ StorageClusterStatusModel.Node node = nodes.next();
+ assertEquals(node.getName(), "test1");
+ assertEquals(node.getStartCode(), 1245219839331L);
+ assertEquals(node.getHeapSizeMB(), 128);
+ assertEquals(node.getMaxHeapSizeMB(), 1024);
+ Iterator<StorageClusterStatusModel.Node.Region> regions =
+ node.getRegions().iterator();
+ StorageClusterStatusModel.Node.Region region = regions.next();
+ assertTrue(Bytes.toString(region.getName()).equals("-ROOT-,,0"));
+ assertEquals(region.getStores(), 1);
+ assertEquals(region.getStorefiles(), 1);
+ assertEquals(region.getStorefileSizeMB(), 0);
+ assertEquals(region.getMemstoreSizeMB(), 0);
+ assertEquals(region.getStorefileIndexSizeMB(), 0);
+ assertFalse(regions.hasNext());
+ node = nodes.next();
+ assertEquals(node.getName(), "test2");
+ assertEquals(node.getStartCode(), 1245239331198L);
+ assertEquals(node.getHeapSizeMB(), 512);
+ assertEquals(node.getMaxHeapSizeMB(), 1024);
+ regions = node.getRegions().iterator();
+ region = regions.next();
+ assertEquals(Bytes.toString(region.getName()), ".META.,,1246000043724");
+ assertEquals(region.getStores(), 1);
+ assertEquals(region.getStorefiles(), 1);
+ assertEquals(region.getStorefileSizeMB(), 0);
+ assertEquals(region.getMemstoreSizeMB(), 0);
+ assertEquals(region.getStorefileIndexSizeMB(), 0);
+ assertFalse(regions.hasNext());
+ assertFalse(nodes.hasNext());
+ }
+
+ public void testBuildModel() throws Exception {
+ checkModel(buildTestModel());
+ }
+
+ public void testFromXML() throws Exception {
+ checkModel(fromXML(AS_XML));
+ }
+
+ public void testFromPB() throws Exception {
+ checkModel(fromPB(AS_PB));
+ }
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestStorageClusterVersionModel.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestStorageClusterVersionModel.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestStorageClusterVersionModel.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestStorageClusterVersionModel.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate.model;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import junit.framework.TestCase;
+
+public class TestStorageClusterVersionModel extends TestCase {
+ private static final String VERSION = "0.0.1-testing";
+
+ private static final String AS_XML =
+ "<ClusterVersion>" + VERSION + "</ClusterVersion>";
+
+ private JAXBContext context;
+
+ public TestStorageClusterVersionModel() throws JAXBException {
+ super();
+ context = JAXBContext.newInstance(StorageClusterVersionModel.class);
+ }
+
+ private StorageClusterVersionModel buildTestModel() {
+ StorageClusterVersionModel model = new StorageClusterVersionModel();
+ model.setVersion(VERSION);
+ return model;
+ }
+
+ @SuppressWarnings("unused")
+ private String toXML(StorageClusterVersionModel model) throws JAXBException {
+ StringWriter writer = new StringWriter();
+ context.createMarshaller().marshal(model, writer);
+ return writer.toString();
+ }
+
+ private StorageClusterVersionModel fromXML(String xml) throws JAXBException {
+ return (StorageClusterVersionModel)
+ context.createUnmarshaller().unmarshal(new StringReader(xml));
+ }
+
+ private void checkModel(StorageClusterVersionModel model) {
+ assertEquals(model.getVersion(), VERSION);
+ }
+
+ public void testBuildModel() throws Exception {
+ checkModel(buildTestModel());
+ }
+
+ public void testFromXML() throws Exception {
+ checkModel(fromXML(AS_XML));
+ }
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableInfoModel.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableInfoModel.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableInfoModel.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableInfoModel.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate.model;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Iterator;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.hadoop.hbase.util.Base64;
+import org.apache.hadoop.hbase.util.Bytes;
+
+import junit.framework.TestCase;
+
+public class TestTableInfoModel extends TestCase {
+ private static final String TABLE = "testtable";
+ private static final byte[] START_KEY = Bytes.toBytes("abracadbra");
+ private static final byte[] END_KEY = Bytes.toBytes("zzyzx");
+ private static final long ID = 8731042424L;
+ private static final String LOCATION = "testhost:9876";
+
+ private static final String AS_XML =
+ "<TableInfo name=\"testtable\">" +
+ "<Region location=\"testhost:9876\"" +
+ " endKey=\"enp5eng=\"" +
+ " startKey=\"YWJyYWNhZGJyYQ==\"" +
+ " id=\"8731042424\"" +
+ " name=\"testtable,abracadbra,8731042424\"/>" +
+ "</TableInfo>";
+
+ private static final String AS_PB =
+ "Cgl0ZXN0dGFibGUSSQofdGVzdHRhYmxlLGFicmFjYWRicmEsODczMTA0MjQyNBIKYWJyYWNhZGJy" +
+ "YRoFenp5engg+MSkwyAqDXRlc3Rob3N0Ojk4NzY=";
+
+ private JAXBContext context;
+
+ public TestTableInfoModel() throws JAXBException {
+ super();
+ context = JAXBContext.newInstance(
+ TableInfoModel.class,
+ TableRegionModel.class);
+ }
+
+ private TableInfoModel buildTestModel() {
+ TableInfoModel model = new TableInfoModel();
+ model.setName(TABLE);
+ model.add(new TableRegionModel(TABLE, ID, START_KEY, END_KEY, LOCATION));
+ return model;
+ }
+
+ @SuppressWarnings("unused")
+ private String toXML(TableInfoModel model) throws JAXBException {
+ StringWriter writer = new StringWriter();
+ context.createMarshaller().marshal(model, writer);
+ return writer.toString();
+ }
+
+ private TableInfoModel fromXML(String xml) throws JAXBException {
+ return (TableInfoModel)
+ context.createUnmarshaller().unmarshal(new StringReader(xml));
+ }
+
+ @SuppressWarnings("unused")
+ private byte[] toPB(TableInfoModel model) {
+ return model.createProtobufOutput();
+ }
+
+ private TableInfoModel fromPB(String pb) throws IOException {
+ return (TableInfoModel)
+ new TableInfoModel().getObjectFromMessage(Base64.decode(AS_PB));
+ }
+
+ private void checkModel(TableInfoModel model) {
+ assertEquals(model.getName(), TABLE);
+ Iterator<TableRegionModel> regions = model.getRegions().iterator();
+ TableRegionModel region = regions.next();
+ assertTrue(Bytes.equals(region.getStartKey(), START_KEY));
+ assertTrue(Bytes.equals(region.getEndKey(), END_KEY));
+ assertEquals(region.getId(), ID);
+ assertEquals(region.getLocation(), LOCATION);
+ assertFalse(regions.hasNext());
+ }
+
+ public void testBuildModel() throws Exception {
+ checkModel(buildTestModel());
+ }
+
+ public void testFromXML() throws Exception {
+ checkModel(fromXML(AS_XML));
+ }
+
+ public void testFromPB() throws Exception {
+ checkModel(fromPB(AS_PB));
+ }
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableListModel.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableListModel.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableListModel.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableListModel.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate.model;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Iterator;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.hadoop.hbase.util.Base64;
+
+import junit.framework.TestCase;
+
+public class TestTableListModel extends TestCase {
+ private static final String TABLE1 = "table1";
+ private static final String TABLE2 = "table2";
+ private static final String TABLE3 = "table3";
+
+ private static final String AS_XML =
+ "<TableList><table name=\"table1\"/><table name=\"table2\"/>" +
+ "<table name=\"table3\"/></TableList>";
+
+ private static final String AS_PB = "CgZ0YWJsZTEKBnRhYmxlMgoGdGFibGUz";
+
+ private JAXBContext context;
+
+ public TestTableListModel() throws JAXBException {
+ super();
+ context = JAXBContext.newInstance(
+ TableListModel.class,
+ TableModel.class);
+ }
+
+ private TableListModel buildTestModel() {
+ TableListModel model = new TableListModel();
+ model.add(new TableModel(TABLE1));
+ model.add(new TableModel(TABLE2));
+ model.add(new TableModel(TABLE3));
+ return model;
+ }
+
+ @SuppressWarnings("unused")
+ private String toXML(TableListModel model) throws JAXBException {
+ StringWriter writer = new StringWriter();
+ context.createMarshaller().marshal(model, writer);
+ return writer.toString();
+ }
+
+ private TableListModel fromXML(String xml) throws JAXBException {
+ return (TableListModel)
+ context.createUnmarshaller().unmarshal(new StringReader(xml));
+ }
+
+ @SuppressWarnings("unused")
+ private byte[] toPB(TableListModel model) {
+ return model.createProtobufOutput();
+ }
+
+ private TableListModel fromPB(String pb) throws IOException {
+ return (TableListModel)
+ new TableListModel().getObjectFromMessage(Base64.decode(AS_PB));
+ }
+
+ private void checkModel(TableListModel model) {
+ Iterator<TableModel> tables = model.getTables().iterator();
+ TableModel table = tables.next();
+ assertEquals(table.getName(), TABLE1);
+ table = tables.next();
+ assertEquals(table.getName(), TABLE2);
+ table = tables.next();
+ assertEquals(table.getName(), TABLE3);
+ assertFalse(tables.hasNext());
+ }
+
+ public void testBuildModel() throws Exception {
+ checkModel(buildTestModel());
+ }
+
+ public void testFromXML() throws Exception {
+ checkModel(fromXML(AS_XML));
+ }
+
+ public void testFromPB() throws Exception {
+ checkModel(fromPB(AS_PB));
+ }
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableRegionModel.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableRegionModel.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableRegionModel.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableRegionModel.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate.model;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.hadoop.hbase.util.Bytes;
+
+import junit.framework.TestCase;
+
+public class TestTableRegionModel extends TestCase {
+ private static final String TABLE = "testtable";
+ private static final byte[] START_KEY = Bytes.toBytes("abracadbra");
+ private static final byte[] END_KEY = Bytes.toBytes("zzyzx");
+ private static final long ID = 8731042424L;
+ private static final String LOCATION = "testhost:9876";
+
+ private static final String AS_XML =
+ "<Region location=\"testhost:9876\"" +
+ " endKey=\"enp5eng=\"" +
+ " startKey=\"YWJyYWNhZGJyYQ==\"" +
+ " id=\"8731042424\"" +
+ " name=\"testtable,abracadbra,8731042424\"/>";
+
+ private JAXBContext context;
+
+ public TestTableRegionModel() throws JAXBException {
+ super();
+ context = JAXBContext.newInstance(TableRegionModel.class);
+ }
+
+ private TableRegionModel buildTestModel() {
+ TableRegionModel model =
+ new TableRegionModel(TABLE, ID, START_KEY, END_KEY, LOCATION);
+ return model;
+ }
+
+ @SuppressWarnings("unused")
+ private String toXML(TableRegionModel model) throws JAXBException {
+ StringWriter writer = new StringWriter();
+ context.createMarshaller().marshal(model, writer);
+ return writer.toString();
+ }
+
+ private TableRegionModel fromXML(String xml) throws JAXBException {
+ return (TableRegionModel)
+ context.createUnmarshaller().unmarshal(new StringReader(xml));
+ }
+
+ private void checkModel(TableRegionModel model) {
+ assertTrue(Bytes.equals(model.getStartKey(), START_KEY));
+ assertTrue(Bytes.equals(model.getEndKey(), END_KEY));
+ assertEquals(model.getId(), ID);
+ assertEquals(model.getLocation(), LOCATION);
+ assertEquals(model.getName(),
+ TABLE + "," + Bytes.toString(START_KEY) + "," + Long.toString(ID));
+ }
+
+ public void testBuildModel() throws Exception {
+ checkModel(buildTestModel());
+ }
+
+ public void testFromXML() throws Exception {
+ checkModel(fromXML(AS_XML));
+ }
+}
Added: hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableSchemaModel.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableSchemaModel.java?rev=928876&view=auto
==============================================================================
--- hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableSchemaModel.java (added)
+++ hadoop/hbase/trunk/contrib/stargate/core/src/test/java/org/apache/hadoop/hbase/stargate/model/TestTableSchemaModel.java Mon Mar 29 19:15:15 2010
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.stargate.model;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Iterator;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.hadoop.hbase.util.Base64;
+
+import junit.framework.TestCase;
+
+public class TestTableSchemaModel extends TestCase {
+
+ public static final String TABLE_NAME = "testTable";
+ private static final boolean IS_META = false;
+ private static final boolean IS_ROOT = false;
+ private static final boolean READONLY = false;
+
+ private static final String AS_XML =
+ "<TableSchema name=\"testTable\"" +
+ " IS_META=\"false\"" +
+ " IS_ROOT=\"false\"" +
+ " READONLY=\"false\">" +
+ TestColumnSchemaModel.AS_XML +
+ "</TableSchema>";
+
+ private static final String AS_PB =
+ "Cgl0ZXN0VGFibGUSEAoHSVNfTUVUQRIFZmFsc2USEAoHSVNfUk9PVBIFZmFsc2USEQoIUkVBRE9O" +
+ "TFkSBWZhbHNlEhIKCUlOX01FTU9SWRIFZmFsc2UamAEKCnRlc3Rjb2x1bW4SEgoJQkxPQ0tTSVpF" +
+ "EgUxNjM4NBIUCgtCTE9PTUZJTFRFUhIFZmFsc2USEgoKQkxPQ0tDQUNIRRIEdHJ1ZRIRCgtDT01Q" +
+ "UkVTU0lPThICZ3oSDQoIVkVSU0lPTlMSATESDAoDVFRMEgU4NjQwMBISCglJTl9NRU1PUlkSBWZh" +
+ "bHNlGICjBSABKgJneiAAKAA=";
+
+ private JAXBContext context;
+
+ public TestTableSchemaModel() throws JAXBException {
+ super();
+ context = JAXBContext.newInstance(
+ ColumnSchemaModel.class,
+ TableSchemaModel.class);
+ }
+
+ public static TableSchemaModel buildTestModel() {
+ return buildTestModel(TABLE_NAME);
+ }
+
+ public static TableSchemaModel buildTestModel(String name) {
+ TableSchemaModel model = new TableSchemaModel();
+ model.setName(name);
+ model.__setIsMeta(IS_META);
+ model.__setIsRoot(IS_ROOT);
+ model.__setReadOnly(READONLY);
+ model.addColumnFamily(TestColumnSchemaModel.buildTestModel());
+ return model;
+ }
+
+ @SuppressWarnings("unused")
+ private String toXML(TableSchemaModel model) throws JAXBException {
+ StringWriter writer = new StringWriter();
+ context.createMarshaller().marshal(model, writer);
+ return writer.toString();
+ }
+
+ private TableSchemaModel fromXML(String xml) throws JAXBException {
+ return (TableSchemaModel)
+ context.createUnmarshaller().unmarshal(new StringReader(xml));
+ }
+
+ @SuppressWarnings("unused")
+ private byte[] toPB(TableSchemaModel model) {
+ return model.createProtobufOutput();
+ }
+
+ private TableSchemaModel fromPB(String pb) throws IOException {
+ return (TableSchemaModel)
+ new TableSchemaModel().getObjectFromMessage(Base64.decode(AS_PB));
+ }
+
+ public static void checkModel(TableSchemaModel model) {
+ checkModel(model, TABLE_NAME);
+ }
+
+ public static void checkModel(TableSchemaModel model, String tableName) {
+ assertEquals(model.getName(), tableName);
+ assertEquals(model.__getIsMeta(), IS_META);
+ assertEquals(model.__getIsRoot(), IS_ROOT);
+ assertEquals(model.__getReadOnly(), READONLY);
+ Iterator<ColumnSchemaModel> families = model.getColumns().iterator();
+ assertTrue(families.hasNext());
+ ColumnSchemaModel family = families.next();
+ TestColumnSchemaModel.checkModel(family);
+ assertFalse(families.hasNext());
+ }
+
+ public void testBuildModel() throws Exception {
+ checkModel(buildTestModel());
+ }
+
+ public void testFromXML() throws Exception {
+ checkModel(fromXML(AS_XML));
+ }
+
+ public void testFromPB() throws Exception {
+ checkModel(fromPB(AS_PB));
+ }
+}