Return-Path: Delivered-To: apmail-hadoop-hbase-commits-archive@minotaur.apache.org Received: (qmail 29905 invoked from network); 28 Jun 2009 18:22:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 28 Jun 2009 18:22:34 -0000 Received: (qmail 46853 invoked by uid 500); 28 Jun 2009 18:22:45 -0000 Delivered-To: apmail-hadoop-hbase-commits-archive@hadoop.apache.org Received: (qmail 46807 invoked by uid 500); 28 Jun 2009 18:22:45 -0000 Mailing-List: contact hbase-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hbase-dev@hadoop.apache.org Delivered-To: mailing list hbase-commits@hadoop.apache.org Received: (qmail 46798 invoked by uid 99); 28 Jun 2009 18:22:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Jun 2009 18:22:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Jun 2009 18:22:40 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BF8A923889B4; Sun, 28 Jun 2009 18:21:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r789136 [8/8] - in /hadoop/hbase/trunk/src/contrib: ./ stargate/ stargate/lib/ stargate/src/ stargate/src/java/ stargate/src/java/org/ stargate/src/java/org/apache/ stargate/src/java/org/apache/hadoop/ stargate/src/java/org/apache/hadoop/hb... Date: Sun, 28 Jun 2009 18:21:49 -0000 To: hbase-commits@hadoop.apache.org From: apurtell@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090628182152.BF8A923889B4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestScannerModel.java URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestScannerModel.java?rev=789136&view=auto ============================================================================== --- hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestScannerModel.java (added) +++ hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestScannerModel.java Sun Jun 28 18:21:45 2009 @@ -0,0 +1,126 @@ +/* + * 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 = + ""; + + 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/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestStorageClusterStatusModel.java URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestStorageClusterStatusModel.java?rev=789136&view=auto ============================================================================== --- hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestStorageClusterStatusModel.java (added) +++ hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestStorageClusterStatusModel.java Sun Jun 28 18:21:45 2009 @@ -0,0 +1,131 @@ +/* + * 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 = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private static final String AS_PB = + "ChsKBXRlc3QxEAAaCS1ST09ULSwsMCDjuovnniQKJwoFdGVzdDIQABoVLk1FVEEuLCwxMjQ2MDAw" + + "MDQzNzI0IP6SsfCeJBgCIAApAAAAAAAA8D8="; + + 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) + .addRegion(Bytes.toBytes("-ROOT-,,0")); + model.addLiveNode("test2", 1245239331198L) + .addRegion(Bytes.toBytes(".META.,,1246000043724")); + 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 nodes = + model.getLiveNodes().iterator(); + StorageClusterStatusModel.Node node = nodes.next(); + assertEquals(node.getName(), "test1"); + assertEquals(node.getStartCode(), 1245219839331L); + Iterator regions = + node.getRegions().iterator(); + StorageClusterStatusModel.Node.Region region = regions.next(); + assertTrue(Bytes.toString(region.getName()).equals("-ROOT-,,0")); + assertFalse(regions.hasNext()); + node = nodes.next(); + assertEquals(node.getName(), "test2"); + assertEquals(node.getStartCode(), 1245239331198L); + regions = node.getRegions().iterator(); + region = regions.next(); + assertEquals(Bytes.toString(region.getName()), ".META.,,1246000043724"); + 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/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestStorageClusterVersionModel.java URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestStorageClusterVersionModel.java?rev=789136&view=auto ============================================================================== --- hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestStorageClusterVersionModel.java (added) +++ hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestStorageClusterVersionModel.java Sun Jun 28 18:21:45 2009 @@ -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 = + "" + VERSION + ""; + + 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/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableInfoModel.java URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableInfoModel.java?rev=789136&view=auto ============================================================================== --- hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableInfoModel.java (added) +++ hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableInfoModel.java Sun Jun 28 18:21:45 2009 @@ -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 = + "" + + "" + + ""; + + 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 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/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableListModel.java URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableListModel.java?rev=789136&view=auto ============================================================================== --- hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableListModel.java (added) +++ hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableListModel.java Sun Jun 28 18:21:45 2009 @@ -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 = + "
" + + "
"; + + 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 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/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableRegionModel.java URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableRegionModel.java?rev=789136&view=auto ============================================================================== --- hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableRegionModel.java (added) +++ hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableRegionModel.java Sun Jun 28 18:21:45 2009 @@ -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 = + ""; + + 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/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableSchemaModel.java URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableSchemaModel.java?rev=789136&view=auto ============================================================================== --- hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableSchemaModel.java (added) +++ hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestTableSchemaModel.java Sun Jun 28 18:21:45 2009 @@ -0,0 +1,133 @@ +/* + * 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 IN_MEMORY = false; + 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 = + "" + + TestColumnSchemaModel.AS_XML + + ""; + + 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.__setInMemory(IN_MEMORY); + 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.__getInMemory(), IN_MEMORY); + assertEquals(model.__getIsMeta(), IS_META); + assertEquals(model.__getIsRoot(), IS_ROOT); + assertEquals(model.__getReadOnly(), READONLY); + Iterator 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)); + } +} Added: hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestVersionModel.java URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestVersionModel.java?rev=789136&view=auto ============================================================================== --- hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestVersionModel.java (added) +++ hadoop/hbase/trunk/src/contrib/stargate/src/test/org/apache/hadoop/hbase/stargate/model/TestVersionModel.java Sun Jun 28 18:21:45 2009 @@ -0,0 +1,112 @@ +/* + * 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 junit.framework.TestCase; + +public class TestVersionModel extends TestCase { + private static final String STARGATE_VERSION = "0.0.1"; + private static final String OS_VERSION = + "Linux 2.6.18-128.1.6.el5.centos.plusxen amd64"; + private static final String JVM_VERSION = + "Sun Microsystems Inc. 1.6.0_13-11.3-b02"; + private static final String JETTY_VERSION = "6.1.14"; + private static final String JERSEY_VERSION = "1.1.0-ea"; + + private static final String AS_XML = + ""; + + private static final String AS_PB = + "CgUwLjAuMRInU3VuIE1pY3Jvc3lzdGVtcyBJbmMuIDEuNi4wXzEzLTExLjMtYjAyGi1MaW51eCAy" + + "LjYuMTgtMTI4LjEuNi5lbDUuY2VudG9zLnBsdXN4ZW4gYW1kNjQiBjYuMS4xNCoIMS4xLjAtZWE="; + + private JAXBContext context; + + public TestVersionModel() throws JAXBException { + super(); + context = JAXBContext.newInstance(VersionModel.class); + } + + private VersionModel buildTestModel() { + VersionModel model = new VersionModel(); + model.setStargateVersion(STARGATE_VERSION); + model.setOsVersion(OS_VERSION); + model.setJvmVersion(JVM_VERSION); + model.setServerVersion(JETTY_VERSION); + model.setJerseyVersion(JERSEY_VERSION); + return model; + } + + @SuppressWarnings("unused") + private String toXML(VersionModel model) throws JAXBException { + StringWriter writer = new StringWriter(); + context.createMarshaller().marshal(model, writer); + return writer.toString(); + } + + private VersionModel fromXML(String xml) throws JAXBException { + return (VersionModel) + context.createUnmarshaller().unmarshal(new StringReader(xml)); + } + + @SuppressWarnings("unused") + private byte[] toPB(VersionModel model) { + return model.createProtobufOutput(); + } + + private VersionModel fromPB(String pb) throws IOException { + return (VersionModel) + new VersionModel().getObjectFromMessage(Base64.decode(AS_PB)); + } + + private void checkModel(VersionModel model) { + assertEquals(model.getStargateVersion(), STARGATE_VERSION); + assertEquals(model.getOsVersion(), OS_VERSION); + assertEquals(model.getJvmVersion(), JVM_VERSION); + assertEquals(model.getServerVersion(), JETTY_VERSION); + assertEquals(model.getJerseyVersion(), JERSEY_VERSION); + } + + 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/src/contrib/stargate/src/test/zoo.cfg URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/contrib/stargate/src/test/zoo.cfg?rev=789136&view=auto ============================================================================== --- hadoop/hbase/trunk/src/contrib/stargate/src/test/zoo.cfg (added) +++ hadoop/hbase/trunk/src/contrib/stargate/src/test/zoo.cfg Sun Jun 28 18:21:45 2009 @@ -0,0 +1,14 @@ +# The number of milliseconds of each tick +tickTime=2000 +# The number of ticks that the initial +# synchronization phase can take +initLimit=10 +# The number of ticks that can pass between +# sending a request and getting an acknowledgement +syncLimit=5 +# the directory where the snapshot is stored. +dataDir=${hbase.tmp.dir}/zookeeper +# the port at which the clients will connect +clientPort=21810 + +server.0=localhost:2888:3888