Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding test cases of datatypes

  • Loading branch information...
commit 9d45a909cc42b56349d6208c742571c66fe60bc5 1 parent aa6a0fd
kkmishra kkmishra authored
2  kundera-core/src/main/java/com/impetus/kundera/persistence/PersistenceDelegator.java
View
@@ -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;
39 kundera-hbase/src/test/java/com/impetus/client/hbase/crud/PersonHBaseTest.java
View
@@ -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)
+
}
}
126 kundera-hbase/src/test/java/com/impetus/client/hbase/junits/HBaseCli.java
View
@@ -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,51 +108,6 @@ 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.
@@ -149,7 +115,7 @@ public void init()
* @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();
+ }
+
}
-
}
12 kundera-hbase/src/test/java/com/impetus/client/hbase/schemaManager/AllTests.java
View
@@ -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
-{
-
-}
18 kundera-hbase/src/test/java/com/impetus/client/hbase/schemaManager/HBaseSchemaManagerTest.java
View
@@ -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
44 kundera-hbase/src/test/java/com/impetus/client/hbase/schemaManager/HBaseSchemaOperationTest.java
View
@@ -67,17 +67,19 @@
private static HBaseAdmin admin;
+ private static HBaseCli cli;
+
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception
{
-
- HBaseCli.startCluster();
+ cli = new HBaseCli();
+ cli.startCluster();
if (admin == null)
{
- admin = HBaseCli.utility.getHBaseAdmin();
+ admin = cli.utility.getHBaseAdmin();
}
}
@@ -97,7 +99,8 @@ public void setUp() throws Exception
@AfterClass
public static void tearDownAfterClass() throws Exception
{
- // HBaseCli.stopCluster();
+ cli.stopCluster();
+
// admin = null;
}
@@ -107,12 +110,12 @@ public static void tearDownAfterClass() throws Exception
@After
public void tearDown() throws Exception
{
- schemaManager.dropSchema();
+ // schemaManager.dropSchema();
// HBaseCli.stopCluster();
// admin= null;
}
- // @Test
+ @Test
public void testCreate() throws IOException
{
getEntityManagerFactory("create");
@@ -139,7 +142,7 @@ public void testCreate() throws IOException
Assert.assertFalse(admin.isTableAvailable("HbaseEntitySimple"));
}
- // @Test
+ @Test
public void testCreatedrop() throws IOException
{
getEntityManagerFactory("create-drop");
@@ -161,17 +164,26 @@ public void testCreatedrop() throws IOException
Assert.assertTrue(columns.contains(columnDescriptor.getNameAsString()));
}
+ // if (admin.isTableAvailable("HbaseEntitySimple"))
+ // {
+ // admin.disableTable("HbaseEntitySimple");
+ // admin.deleteTable("HbaseEntitySimple");
+ // }
schemaManager.dropSchema();
Assert.assertFalse(admin.isTableAvailable("HbaseEntitySimple"));
}
- // @Test
+ @Test
public void testUpdate() throws IOException
{
HTableDescriptor descriptor1 = new HTableDescriptor("HbaseEntitySimple");
HColumnDescriptor columnDescriptor1 = new HColumnDescriptor("PERSON_NAME");
descriptor1.addFamily(columnDescriptor1);
-
+ if (admin.isTableAvailable("HbaseEntitySimple"))
+ {
+ admin.disableTable("HbaseEntitySimple");
+ admin.deleteTable("HbaseEntitySimple");
+ }
admin.createTable(descriptor1);
Assert.assertTrue(admin.isTableAvailable("HbaseEntitySimple"));
HTableDescriptor descriptor2 = admin.getTableDescriptor("HbaseEntitySimple".getBytes());
@@ -216,7 +228,11 @@ public void testValidate() throws IOException
descriptor1.addFamily(columnDescriptor1);
HColumnDescriptor columnDescriptor2 = new HColumnDescriptor("AGE");
descriptor1.addFamily(columnDescriptor2);
-
+ if (admin.isTableAvailable("HbaseEntitySimple"))
+ {
+ admin.disableTable("HbaseEntitySimple");
+ admin.deleteTable("HbaseEntitySimple");
+ }
admin.createTable(descriptor1);
Assert.assertTrue(admin.isTableAvailable("HbaseEntitySimple"));
@@ -250,7 +266,11 @@ public void testValidateInValid() throws IOException
HTableDescriptor descriptor1 = new HTableDescriptor("HbaseEntitySimple");
HColumnDescriptor columnDescriptor1 = new HColumnDescriptor("PERSON_NAME");
descriptor1.addFamily(columnDescriptor1);
-
+ if (admin.isTableAvailable("HbaseEntitySimple"))
+ {
+ admin.disableTable("HbaseEntitySimple");
+ admin.deleteTable("HbaseEntitySimple");
+ }
admin.createTable(descriptor1);
Assert.assertTrue(admin.isTableAvailable("HbaseEntitySimple"));
HTableDescriptor descriptor2 = admin.getTableDescriptor("HbaseEntitySimple".getBytes());
@@ -307,7 +327,9 @@ private EntityManagerFactoryImpl getEntityManagerFactory(String property)
clientMetadata.setLuceneIndexDir(null);
}
+ KunderaMetadata.INSTANCE.setApplicationMetadata(null);
ApplicationMetadata appMetadata = KunderaMetadata.INSTANCE.getApplicationMetadata();
+ // appMetadata = null;
PersistenceUnitMetadata puMetadata = new PersistenceUnitMetadata();
puMetadata.setPersistenceUnitName(persistenceUnit);
Properties p = new Properties();
2  kundera-hbase/src/test/resources/META-INF/persistence.xml
View
@@ -17,7 +17,7 @@
<property name="kundera.cache.provider.class"
value="com.impetus.kundera.cache.ehcache.EhCacheProvider" />
<property name="kundera.cache.config.resource" value="/ehcache-test.xml" />
- <property name="index_home_dir" value="/home/impadmin/lucene" />
+ <property name="index_home_dir" value="./lucene" />
</properties>
</persistence-unit>
</persistence>
1  kundera-mongo/src/main/java/com/impetus/client/mongodb/MongoDBDataHandler.java
View
@@ -31,7 +31,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import com.impetus.kundera.client.Client;
import com.impetus.kundera.client.EnhanceEntity;
import com.impetus.kundera.db.RelationHolder;
import com.impetus.kundera.metadata.model.Column;
4 kundera-rdbms/src/main/java/com/impetus/client/rdbms/query/RDBMSEntityReader.java
View
@@ -305,8 +305,10 @@ public String getSqlQueryFromJPA(EntityMetadata entityMetadata, List<String> rel
String fieldName = clause.getProperty();
boolean isString = isStringProperty(entityMetadata, fieldName);
+// queryBuilder.append(StringUtils.replace(clause.getProperty(),
+// clause.getProperty().substring(0, clause.getProperty().indexOf(".")), aliasName));
queryBuilder.append(StringUtils.replace(clause.getProperty(),
- clause.getProperty().substring(0, clause.getProperty().indexOf(".")), aliasName));
+ aliasName, aliasName));
queryBuilder.append(" ");
queryBuilder.append(clause.getCondition());
79 kundera-rdbms/src/test/resources/META-INF/persistence.xml
View
@@ -1,51 +1,54 @@
-<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
https://raw.github.com/impetus-opensource/Kundera/Kundera-2.0.4/kundera-core/src/test/resources/META-INF/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="testHibernate">
<provider>com.impetus.kundera.KunderaPersistence</provider>
- <class>com.impetus.client.Player</class>
- <class>com.impetus.client.onetoone.OTONPerson</class>
- <class>com.impetus.client.onetoone.OTONSPerson</class>
- <class>com.impetus.client.onetomany.OTMNPerson</class>
- <class>com.impetus.client.onetomany.bi.OTMBNPerson</class>
- <class>com.impetus.client.manytoone.MTONPerson</class>
- <class>com.impetus.client.manytomany.MTMNPerson</class>
- <class>com.impetus.client.onetoone.OTOAddress</class>
- <class>com.impetus.client.onetoone.OTOSAddress</class>
- <class>com.impetus.client.onetomany.OTMAddress</class>
- <class>com.impetus.client.onetomany.bi.OTMBAddress</class>
- <class>com.impetus.client.manytoone.MTOAddress</class>
- <class>com.impetus.client.manytomany.MTMAddress</class>
- <properties>
-<!-- <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
- --> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
- <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
- <property name="hibernate.connection.url" value="jdbc:mysql://localhost/test"/>
- <property name="hibernate.connection.username" value="root"/>
- <property name="kundera.client" value="rdbms"/>
+ <class>com.impetus.client.Player</class>
+ <class>com.impetus.client.onetoone.OTONPerson</class>
+ <class>com.impetus.client.onetoone.OTONSPerson</class>
+ <class>com.impetus.client.onetomany.OTMNPerson</class>
+ <class>com.impetus.client.onetomany.bi.OTMBNPerson</class>
+ <class>com.impetus.client.manytoone.MTONPerson</class>
+ <class>com.impetus.client.manytomany.MTMNPerson</class>
+ <class>com.impetus.client.onetoone.OTOAddress</class>
+ <class>com.impetus.client.onetoone.OTOSAddress</class>
+ <class>com.impetus.client.onetomany.OTMAddress</class>
+ <class>com.impetus.client.onetomany.bi.OTMBAddress</class>
+ <class>com.impetus.client.manytoone.MTOAddress</class>
+ <class>com.impetus.client.manytomany.MTMAddress</class>
+ <properties>
+ <property name="hibernate.hbm2ddl.auto" value="create" />
+ <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
+ <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
+ <property name="hibernate.connection.url" value="jdbc:mysql://localhost/test" />
+ <property name="hibernate.connection.username" value="root" />
+ <property name="kundera.client" value="rdbms" />
<property name="kundera.client.lookup.class" value="com.impetus.client.rdbms.RDBMSClientFactory" />
- <property name="hibernate.connection.password" value="impetus"/>
- <property name="hibernate.current_session_context_class" value="org.hibernate.context.ThreadLocalSessionContext" />
- <property name="hibernate.show_sql" value="true"/>
- <property name="hibernate.format_sql" value="true"/>
-
+ <property name="hibernate.connection.password" value="impetus" />
+ <property name="hibernate.current_session_context_class"
+ value="org.hibernate.context.ThreadLocalSessionContext" />
+ <property name="hibernate.show_sql" value="true" />
+ <property name="hibernate.format_sql" value="true" />
+
</properties>
-
+
</persistence-unit>
-
- <persistence-unit name="kcassandra">
+
+ <persistence-unit name="kcassandra">
<provider>com.impetus.kundera.KunderaPersistence</provider>
- <properties>
- <property name="kundera.nodes" value="localhost"/>
- <property name="kundera.port" value="9160"/>
- <property name="kundera.keyspace" value="KunderaKeyspace"/>
- <property name="kundera.dialect" value="cassandra"/>
- <property name="kundera.client" value="Pelops"/>
- <property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider"/>
+ <properties>
+ <property name="kundera.nodes" value="localhost" />
+ <property name="kundera.port" value="9160" />
+ <property name="kundera.keyspace" value="KunderaKeyspace" />
+ <property name="kundera.dialect" value="cassandra" />
+ <property name="kundera.client" value="Pelops" />
+ <property name="kundera.cache.provider.class"
+ value="com.impetus.kundera.cache.ehcache.EhCacheProvider" />
</properties>
-
+
</persistence-unit>
-
+
</persistence>
1  pom.xml
View
@@ -131,6 +131,7 @@
<module>kundera-hbase</module>
<module>kundera-mongo</module>
<module>kundera-rdbms</module>
+ <module>kundera-tests</module>
</modules>
</profile>
Please sign in to comment.
Something went wrong with that request. Please try again.