Permalink
Browse files

JAMES-1395

- all tests pass 



git-svn-id: https://svn.apache.org/repos/asf/james/server/trunk@1302797 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 5ca6618 commit 7565b59a8e2d75cbe1cacc15de89edcacaec9434 Ioan Eugen Stan committed Mar 20, 2012
View
@@ -168,9 +168,6 @@
<argLine>-Xms256m -Xmx512m</argLine>
<testFailureIgnore>false</testFailureIgnore>
<skip>false</skip>
- <includes>
- <include>**/*SuiteTest.java</include>
- </includes>
</configuration>
</plugin>
</plugins>
@@ -19,7 +19,6 @@
package org.apache.james.system.hbase;
import java.io.IOException;
-
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
@@ -35,24 +34,24 @@
/**
* Table Pool singleton to get the DomainList, RecipientRewriteTable and UserRepository HBase tables.
- *
+ *
* TODO Two getInstance methods are public, one for the impl, one for the tests. This is not good.
*/
-public class TablePool {
-
+public class TablePool {
+
private static Configuration configuration;
private static TablePool hbaseSchema;
private static HTablePool htablePool;
-
+
/**
* Use getInstance to get an instance of the {@link HTablePool}.
- *
+ *
* Don't give any configuration, the default one will be used
* via {@link HBaseConfiguration#create(Configuration)}.
- *
+ *
* If you want to create the instance with a specific {@link HBaseConfiguration},
* use {@link #getInstance(Configuration)}
- *
+ *
* @return An instance using a default configuration
* @throws IOException
*/
@@ -62,9 +61,9 @@ public static synchronized TablePool getInstance() throws IOException {
/**
* Use getInstance to get an instance of the {@link HTablePool}.
- *
+ *
* You can give at first call a specific {@link HBaseConfiguration} to suit your needs.
- *
+ *
* @param configuration
* @return An instance of {@link HTablePool}
* @throws IOException
@@ -80,10 +79,10 @@ public static synchronized TablePool getInstance(Configuration configuration) th
}
return hbaseSchema;
}
-
+
/**
* Get an instance of the {@link HDomainList} table.
- *
+ *
* @return An instance of {@link HDomainList}
*/
public HTable getDomainlistTable() {
@@ -92,7 +91,7 @@ public HTable getDomainlistTable() {
/**
* Get an instance of the RecipientRewriteTable table.
- *
+ *
* @return An instance of {@link RecipientRewriteTable}
*/
public HTable getRecipientRewriteTable() {
@@ -101,7 +100,7 @@ public HTable getRecipientRewriteTable() {
/**
* Get an instance of the UsersRepository table.
- *
+ *
* @return An instance of {@link UsersRepository}
*/
public HTable getUsersRepositoryTable() {
@@ -110,20 +109,19 @@ public HTable getUsersRepositoryTable() {
/**
* Create a table if needed.
- *
+ *
* @param tableName
* @param columnFamilyName
* @throws IOException
*/
private static void ensureTable(byte[] tableName, byte[] columnFamilyName) throws IOException {
HBaseAdmin hbaseAdmin = new HBaseAdmin(configuration);
- if (! hbaseAdmin.tableExists(tableName)) {
- HTableDescriptor desc = new HTableDescriptor(tableName);
- HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(columnFamilyName);
- hColumnDescriptor.setMaxVersions(1);
- desc.addFamily(hColumnDescriptor);
- hbaseAdmin.createTable(desc);
+ if (!hbaseAdmin.tableExists(tableName)) {
+ HTableDescriptor desc = new HTableDescriptor(tableName);
+ HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(columnFamilyName);
+ hColumnDescriptor.setMaxVersions(1);
+ desc.addFamily(hColumnDescriptor);
+ hbaseAdmin.createTable(desc);
}
}
-
}
@@ -1,115 +0,0 @@
-/****************************************************************
- * 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.james;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseTestingUtility;
-import org.apache.hadoop.hbase.MiniHBaseCluster;
-import org.apache.hadoop.hbase.client.NoServerForRegionException;
-import org.apache.james.domainlist.hbase.HBaseDomainListTest;
-import org.apache.james.rrt.hbase.HBaseRecipientRewriteTableTest;
-import org.apache.james.system.hbase.TablePool;
-import org.apache.james.system.hbase.TablePoolTest;
-import org.apache.james.user.hbase.HBaseUsersRepositoryTest;
-import org.apache.log4j.Logger;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.junit.runners.Suite.SuiteClasses;
-
-/**
- * Integration Tests for the HBase persistence implementations.
- *
- * Launches a Mini HBase Cluster and run the others tests
- * via a JUnit Test Suite.
- */
-@RunWith(Suite.class)
-@SuiteClasses({
-// TablePoolTest.class,
-// HBaseDomainListTest.class,
-// HBaseRecipientRewriteTableTest.class,
-// HBaseUsersRepositoryTest.class
- })
-public class JamesServerHBaseSuiteTest {
-
- /**
- * The Logger.
- */
- private static Logger logger = Logger.getLogger(JamesServerHBaseSuiteTest.class);
-
- /**
- * In Memory HBase Mini Cluster.
- */
- private static MiniHBaseCluster hbaseCluster;
-
- /**
- * Launches the HBase Mini Cluster before the tests.
- *
- * @throws Exception
- */
-
-// @BeforeClass
- public static void setup() throws Throwable {
- HBaseTestingUtility htu = new HBaseTestingUtility();
- htu.getConfiguration().setBoolean("dfs.support.append", true);
- htu.getConfiguration().setInt("zookeeper.session.timeout", 20000);
- htu.getConfiguration().setInt("hbase.client.retries.number", 2);
- try {
- hbaseCluster = htu.startMiniCluster();
- hbaseCluster.waitForActiveAndReadyMaster();
-
- } catch (NoServerForRegionException e) {
- logger.error("Cannot connect to HBase mini-cluster, and so cannot run tests.");
- logger.error("Some network configurations are known to cause this problem. " +
- "Workarounds are available.");
- logger.error("See https://issues.apache.org/jira/browse/JAMES-1309 for more details.");
- logger.error(e.getMessage(), e);
- throw e.fillInStackTrace();
- } catch (Exception e) {
- logger.error("HBase Mini Cluster failed to start.", e);
- throw e.fillInStackTrace();
- }
- TablePool.getInstance(getConfiguration());
- }
-
- /**
- * Shutdowns the HBase Mini Cluster after the tests.
- *
- * @throws Exception
- */
-// @AfterClass
- public static void tearDown() throws Exception {
- if (hbaseCluster != null) {
- hbaseCluster.shutdown();
- }
- }
-
- /**
- * @return the HBase Configuration
- */
- public static Configuration getConfiguration() {
- if (hbaseCluster == null) {
- throw new IllegalStateException("Please instanciate HBaseTestingUtility before invoking this method");
- }
- return hbaseCluster.getConfiguration();
- }
-
-}
@@ -18,18 +18,30 @@
****************************************************************/
package org.apache.james.domainlist.hbase;
+import java.io.IOException;
import org.apache.james.domainlist.api.DomainList;
import org.apache.james.domainlist.lib.AbstractDomainListTest;
+import org.apache.james.mailbox.hbase.HBaseClusterSingleton;
+import org.apache.james.system.hbase.TablePool;
+import org.junit.Before;
+import org.junit.BeforeClass;
import org.slf4j.LoggerFactory;
/**
* Tests for the HBase DomainList implementation.
- *
+ *
* Simply create the needed HBaseDomainList instance, and let the
* AbstractDomainListTest run the tests
*/
public class HBaseDomainListTest extends AbstractDomainListTest {
+ private static HBaseClusterSingleton cluster = HBaseClusterSingleton.build();
+
+ @BeforeClass
+ public static void setMeUp() throws IOException {
+ TablePool.getInstance(cluster.getConf());
+ }
+
/**
* @see org.apache.james.domainlist.lib.AbstractDomainListTest#createDomainList()
*/
@@ -42,5 +54,4 @@ protected DomainList createDomainList() {
domainList.setAutoDetectIP(false);
return domainList;
}
-
}
@@ -18,16 +18,20 @@
****************************************************************/
package org.apache.james.rrt.hbase;
+import java.io.IOException;
import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.james.mailbox.hbase.HBaseClusterSingleton;
import org.apache.james.rrt.api.RecipientRewriteTableException;
import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
import org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest;
+import org.apache.james.system.hbase.TablePool;
import org.apache.log4j.Logger;
+import org.junit.Before;
import org.slf4j.LoggerFactory;
/**
* Tests for the HBase RecipientRewriteTable implementation.
- *
+ *
* Simply create the needed HBaseRecipientRewriteTable instance, and let the
* AbstractRecipientRewriteTableTest run the tests.
*/
@@ -37,6 +41,12 @@
* The Logger.
*/
private static Logger logger = Logger.getLogger(HBaseRecipientRewriteTableTest.class);
+ private static HBaseClusterSingleton cluster = HBaseClusterSingleton.build();
+
+ @Before
+ public void setMeUp() throws IOException {
+ TablePool.getInstance(cluster.getConf());
+ }
/**
* @see org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest#getRecipientRewriteTable()
@@ -19,22 +19,30 @@
package org.apache.james.system.hbase;
import java.io.IOException;
-
import junit.framework.Assert;
-
+import org.apache.james.mailbox.hbase.HBaseClusterSingleton;
+import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
/**
* Simple tests for the TablePool singleton class.
* Check that the returned singleton and table instances and not null.
*/
public class TablePoolTest {
-
+
+ private static HBaseClusterSingleton cluster = HBaseClusterSingleton.build();
+
+ @BeforeClass
+ public static void setMeUp() throws IOException {
+ TablePool.getInstance(cluster.getConf());
+ }
+
@Test
public void testGetInstance() throws IOException {
Assert.assertNotNull(TablePool.getInstance());
}
-
+
@Test
public void testGetDomainlistTable() throws IOException {
Assert.assertNotNull(TablePool.getInstance().getDomainlistTable());
@@ -49,5 +57,4 @@ public void testGetRecipientRewriteTable() throws IOException {
public void testGetUsersRepositoryTable() throws IOException {
Assert.assertNotNull(TablePool.getInstance().getUsersRepositoryTable());
}
-
}
Oops, something went wrong.

0 comments on commit 7565b59

Please sign in to comment.