Permalink
Browse files

adding test cases of datatypes

  • Loading branch information...
1 parent aa6a0fd commit 9d45a909cc42b56349d6208c742571c66fe60bc5 @kkmishra kkmishra committed May 28, 2012
@@ -49,8 +49,6 @@
import com.impetus.kundera.lifecycle.states.TransientState;
import com.impetus.kundera.metadata.KunderaMetadataManager;
import com.impetus.kundera.metadata.model.EntityMetadata;
-import com.impetus.kundera.metadata.model.JoinTableMetadata;
-import com.impetus.kundera.metadata.model.Relation;
import com.impetus.kundera.persistence.context.FlushManager;
import com.impetus.kundera.persistence.context.FlushStack;
import com.impetus.kundera.persistence.context.MainCache;
@@ -24,6 +24,8 @@
private Map<Object, Object> col;
+ private HBaseCli cli;
+
/**
* Sets the up.
*
@@ -33,18 +35,22 @@
@Before
public void setUp() throws Exception
{
+ cli = new HBaseCli();
+// cli.init();
+ cli.startCluster();
emf = Persistence.createEntityManagerFactory("hbaseTest");
em = emf.createEntityManager();
col = new java.util.HashMap<Object, Object>();
}
-
+
@Test
public void onInsertHbase() throws Exception
{
- HBaseCli.startCluster();
- HBaseCli.createTable("PERSON");
- HBaseCli.addColumnFamily("PERSON", "PERSON_NAME");
- HBaseCli.addColumnFamily("PERSON", "AGE");
+ // if (!cli.isStarted)
+// cli.startCluster();
+ cli.createTable("PERSON");
+ cli.addColumnFamily("PERSON", "PERSON_NAME");
+ cli.addColumnFamily("PERSON", "AGE");
Object p1 = prepareHbaseInstance("1", 10);
Object p2 = prepareHbaseInstance("2", 20);
Object p3 = prepareHbaseInstance("3", 15);
@@ -85,17 +91,24 @@ public void onInsertHbase() throws Exception
*/
@After
public void tearDown() throws Exception
- {/*
- * Delete is working, but as row keys are not deleted from cassandra, so
- * resulting in issue while reading back. // Delete
- * em.remove(em.find(Person.class, "1")); em.remove(em.find(Person.class,
- * "2")); em.remove(em.find(Person.class, "3")); em.close(); emf.close();
- * em = null; emf = null;
- */
+ {
+ /*
+ * Delete is working, but as row keys are not deleted from cassandra, so
+ * resulting in issue while reading back. // Delete
+ * em.remove(em.find(Person.class, "1"));
+ * em.remove(em.find(Person.class, "2"));
+ * em.remove(em.find(Person.class, "3")); em.close(); emf.close(); em =
+ * null; emf = null;
+ */
for (Object val : col.values())
{
em.remove(val);
}
-// HBaseCli.stopCluster();
+ em.close();
+ emf.close();
+ cli.stopCluster("PERSON");
+ // TestUtilities.cleanLuceneDirectory("hbaseTest");
+ // if (cli.isStarted)
+
}
}
@@ -19,18 +19,19 @@
import java.io.IOException;
import java.net.MalformedURLException;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.InvalidFamilyOperationException;
-import org.apache.hadoop.hbase.client.Get;
-import org.apache.hadoop.hbase.client.HTable;
-import org.apache.hadoop.hbase.client.Put;
-import org.apache.hadoop.hbase.client.Result;
-import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.client.HTablePool;
import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
+import org.apache.zookeeper.jmx.ZKMBeanInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,19 +44,24 @@
public class HBaseCli
{
/** The utility. */
- public static HBaseTestingUtility utility;
+ public HBaseTestingUtility utility;
- private static Boolean isStarted = false;
+ public Boolean isStarted = false;
private static final Logger logger = LoggerFactory.getLogger(HBaseCli.class);
+ File zkDir ;
+ File masterDir;
+ MiniZooKeeperCluster zkCluster;
+
+ private HTablePool hTablePool;
public static void main(String arg[])
{
HBaseCli cli = new HBaseCli();
- cli.init();
+ //s cli.init();
}
- public static void startCluster()
+ public void startCluster()
{
if (!isStarted)
{
@@ -69,7 +75,8 @@ public static void startCluster()
conf.set("hbase.zookeeper.property.clientPort", "2181");
try
{
- conf.set(HConstants.HBASE_DIR, new File(workingDirectory, "hbase").toURI().toURL().toString());
+ masterDir = new File(workingDirectory, "hbase");
+ conf.set(HConstants.HBASE_DIR, masterDir.toURI().toURL().toString());
}
catch (MalformedURLException e1)
{
@@ -78,12 +85,16 @@ public static void startCluster()
Configuration hbaseConf = HBaseConfiguration.create(conf);
utility = new HBaseTestingUtility(hbaseConf);
+ hTablePool = new HTablePool(conf, 1);
try
{
- MiniZooKeeperCluster zkCluster = new MiniZooKeeperCluster(conf);
+ zkCluster = new MiniZooKeeperCluster(conf);
zkCluster.setClientPort(2181);
zkCluster.setTickTime(18000);
- zkCluster.startup(utility.setupClusterTestBuildDir());
+ zkDir = utility.setupClusterTestBuildDir();
+ System.out.println("*******************************"+zkDir.getAbsolutePath());
+
+ zkCluster.startup(zkDir);
utility.setZkCluster(zkCluster);
utility.startMiniCluster();
utility.getHbaseCluster().startMaster();
@@ -97,59 +108,14 @@ public static void startCluster()
}
}
- public void init()
- {
- File workingDirectory = new File("./");
- Configuration conf = new Configuration();
- System.setProperty("test.build.data", workingDirectory.getAbsolutePath());
- conf.set("test.build.data", new File(workingDirectory, "zookeeper").getAbsolutePath());
- conf.set("fs.default.name", "file:///");
- try
- {
- conf.set(HConstants.HBASE_DIR, new File(workingDirectory, "hbase").toURI().toURL().toString());
- }
- catch (MalformedURLException e1)
- {
- logger.error(e1.getMessage());
- }
-
- Configuration hbaseConf = HBaseConfiguration.create(conf);
- HBaseTestingUtility utility = new HBaseTestingUtility(hbaseConf);
- try
- {
- utility.startMiniCluster();
- HTable table = utility.createTable("test".getBytes(), "testcol".getBytes());
- utility.getHBaseAdmin().disableTable("test");
- utility.getHBaseAdmin().addColumn("test", new HColumnDescriptor("testColFamily"));
- utility.getHBaseAdmin().enableTable("test");
- logger.info("Server is running : " + utility.getHBaseAdmin().isMasterRunning());
-
- Put p = new Put(Bytes.toBytes("1"));
- p.add(Bytes.toBytes("testColFamily"), Bytes.toBytes("col1"), "col1".getBytes());
- table.put(p);
- logger.info("Table exist:" + utility.getHBaseAdmin().tableExists("test"));
- Get g = new Get(Bytes.toBytes("1"));
- Result r = table.get(g);
- logger.info("Row count:" + r.list().size());
- utility.getHBaseAdmin().disableTable("test");
- logger.info("Deleting table...");
- utility.getHBaseAdmin().deleteTable("test");
- logger.info("Shutting down now...");
- utility.shutdownMiniCluster();
- }
- catch (Exception e)
- {
- logger.error(e.getMessage());
- }
- }
/**
* Creates the table.
*
* @param tableName
* the table name
*/
- public static void createTable(String tableName)
+ public void createTable(String tableName)
{
try
{
@@ -168,6 +134,18 @@ public static void createTable(String tableName)
}
}
+ public void createTable(byte[] tableName, byte[][] families)
+ {
+ try
+ {
+ utility.createTable(tableName, families);
+ }
+ catch (IOException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
/**
* Adds the column family.
*
@@ -176,13 +154,14 @@ public static void createTable(String tableName)
* @param columnFamily
* the column family
*/
- public static void addColumnFamily(String tableName, String columnFamily)
+ public void addColumnFamily(String tableName, String columnFamily)
{
try
{
utility.getHBaseAdmin().disableTable(tableName);
utility.getHBaseAdmin().addColumn(tableName, new HColumnDescriptor(columnFamily));
utility.getHBaseAdmin().enableTable(tableName);
+
}
catch (InvalidFamilyOperationException ife)
{
@@ -194,25 +173,46 @@ public static void addColumnFamily(String tableName, String columnFamily)
}
}
-
-
/**
* Destroys cluster.
*/
- public static void stopCluster()
+ public void stopCluster(String...tableName)
{
try
{
if (utility != null)
{
+ // utility.getMiniHBaseCluster().shutdown();
+// File workingDirectory = new File("./");
+// utility.closeRegion("localhost");
+ utility.cleanupTestDir();
+// utility.cleanupTestDir(dir.getAbsolutePath());
+// ZooKeeperServer server = new ZooKeeperServer(zkDir, zkDir, 2000);
+// ZooKeeperServerBean bean = new ZooKeeperServerBean(server);
+// String path = (String)this.makeFullPath(null,bean);
+// System.out.println("***************" + bean.toString());
+
+// MBeanS
+// MBeanRegistry.getInstance().unregister(bean);
+// MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+// mbs.unregisterMBean(makeObjectName(path,bean));
+// utility.getHbaseCluster().shutdown();
utility.shutdownMiniCluster();
+ FileUtil.fullyDelete(zkDir);
+ FileUtil.fullyDelete(masterDir);
utility = null;
+ isStarted = false;
}
}
catch (IOException e)
{
logger.error(e.getMessage());
}
+ catch (NullPointerException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
}
-
}
@@ -1,12 +0,0 @@
-package com.impetus.client.hbase.schemaManager;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.junit.runners.Suite.SuiteClasses;
-
-@RunWith(Suite.class)
-@SuiteClasses({ HBaseSchemaOperationTest.class, HBaseSchemaManagerTest.class })
-public class AllTests
-{
-
-}
@@ -78,6 +78,8 @@
private ApplicationMetadata appMetadata;
+ private HBaseCli cli;
+
/** The Constant logger. */
private static final Logger logger = LoggerFactory.getLogger(HBaseSchemaManagerTest.class);
@@ -90,11 +92,13 @@
@Before
public void setUp() throws Exception
{
+ cli = new HBaseCli();
logger.info("starting server");
- HBaseCli.startCluster();
+ // if (!HBaseCli.isStarted)
+ cli.startCluster();
if (admin == null)
{
- admin = HBaseCli.utility.getHBaseAdmin();
+ admin = cli.utility.getHBaseAdmin();
}
configuration = new SchemaConfiguration("hbase");
@@ -109,14 +113,20 @@ public void setUp() throws Exception
@After
public void tearDown() throws Exception
{
- HBaseCli.stopCluster();
+ // if (HBaseCli.isStarted)
+ cli.stopCluster();
appMetadata = null;
}
+ @Test
+ public void testDu()
+ {
+
+ }
/**
* Test schema operation.
*/
- @Test
+// @Test
public void testSchemaOperation()
{
try
Oops, something went wrong.

0 comments on commit 9d45a90

Please sign in to comment.