Hyperic 4.5 Released

Engineering
Jennifer Hickey
November 10, 2010

After many months of development, I am proud to announce the release of Hyperic 4.5. In this release, we migrated Hyperic from an EJB application running on JBoss to a Spring web application running on Tomcat. The detailed migration steps are covered in my Case Study on Migrating Hyperic from EJB to Spring, originally presented at the recent SpringOne 2GX. In this post, I would like to highlight a few of my favorite things about the conversion.
Improved testability

Switching to Spring allowed us to convert our existing Stateless Session EJBs to POJOs with autowired dependencies. This eliminated quite a bit of static JNDI lookup code that made unit testing so difficult. Spring also made integration testing significantly easier. Before the conversion, we had a handful of integration tests that each took several minutes to bootstrap an approximation of an EJB container. This process was cumbersome and error prone. Additionally, the tests often left the database in an inconsistent state, making it necessary to add database setup or tear down code, adding additional overhead to test execution time and occasionally causing inconsistent test results.

After the conversion, we were able to take advantage of Spring’s integration testing support to test our new service layer of converted EJBs as well as their underlying DAOs. By simply adding a few annotations, we were able to bootstrap our entire application context in less than 30 seconds and run each test method in a dedicated transaction that was automatically rolled back at the end of the test. This support proved very valuable in allowing us to quickly increase our test coverage by 18% and 12% in our open source and enterprise codebases respectively.

@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = “classpath*:META-INF/spring/*-context.xml”)
public class AppdefManagerTest {

@Autowired
private AppdefManager appdefManager;

@Before
public void setUp() throws Exception {
createPlatformType(“TestPlatform”, “test”);
}

@Test
public void testGetControllablePlatformTypes() throws Exception {
Map<String, AppdefEntityID> platformTypes = appdefManager
.getControllablePlatformTypes(subject);
assertEquals(1, platformTypes.size());
assertEquals(“TestPlatform”, platformTypes.keySet().iterator().next());
}
}

Reduced code complexity

Simply introducing Spring for dependency injection greatly simplified the code in many areas by eliminating verbose dependency lookup. However, there are many other places where introduction of Spring significantly improved the clarity of code, reducing the clutter of infrastructure and allowing us to focus on the true business logic. Two of my favorite examples of this in Hyperic are the usage of JmsTemplate for publishing JMS messages and JdbcTemplate for data access.
Message Publishing Before

public void publishMessage(String name, Serializable sObj) {
TopicConnection conn = null;
TopicSession session = null;
if (_ic == null)
_ic = new InitialContext();
if (_factory == null)
_factory = _ic.lookup(CONN_FACTORY_JNDI);
TopicConnectionFactory tFactory = (TopicConnectionFactory) _factory;
Topic topic = getTopic(name);
if (topic != null) {
// Now create a connection to send a message
if (_tConn != null)
conn = _tConn;
else
conn = tFactory.createTopicConnection();
if (conn == null)
_log.error(“TopicConnection cannot be created”);
if (_tSession != null)
session = _tSession;
else
session = conn.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
// Create a publisher and publish the message
TopicPublisher publisher = session.createPublisher(topic);
ObjectMessage msg = session.createObjectMessage();
msg.setObject(sObj);
publisher.publish(msg);

}

Message Publishing After

public void publishMessage(String name, Serializable sObj) {
eventsJmsTemplate.convertAndSend(name, sObj);
}

Data Access Before

public int getServicesCount(AuthzSubject subject) {
Statement stmt = null;
ResultSet rs = null;
Integer subjectId = subject.getId();
try {
Connection conn = getDBConn();
String sql = “SELECT COUNT(SVC.ID) FROM TBL_SERVICE”;
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next()) {
return rs.getInt(1);
}
} catch (SQLException e) {
log.error("Caught SQL Exception finding Services by type: " + e, e);
throw new SystemException(e);
} finally {
DBUtil.closeJDBCObjects(LOG_CTX, null, stmt, rs);
}
return 0;
}

Data Access After

public int getServicesCount(AuthzSubject subject) {
return jdbcTemplate.queryForInt(“SELECT COUNT(SVC.ID) FROM TBL_SERVICE”);
}

That’s quite a weight loss plan! Simply by converting to Spring and not changing any functionality, we reduced both the open source and enterprise codebases by approximately 7%.
Improved developer productivity

As mentioned above, the Spring support for integration testing allows us to bootstrap our entire application context in less than 30 seconds for end-to-end integration testing. This has been a huge time-saver when testing new features or debugging problems. When we do need to bring up the entire web application, the switch to Tomcat has improved our productivity by significantly decreasing startup time. A single developer coding and debugging an application now saves approximately 5 minutes of waiting each time he/she starts up the application. Considering that developer may restart the application 12 times a day, that frees up an entire hour per day to develop new features! Additionally, the cleaner code and improved unit testability has made it faster and easier to find and fix problems, and the flexible architecture makes it easier to add new features and enhancements.

These are just a few of the benefits provided by switching to Spring and Tomcat in this release. There are really just too many to list in a single blog post!

This release also contains monitoring and management for three of the VMware vFabric platform services, including vFabric GemFire 6.5 distributed caching system, RabbitMQ enterprise messaging system, and the new vFabric tc Server 2.1 Java runtime server also released this week. Support for vFabric tc Server existed in previous releases of Hyperic; however, in 4.5 the plugin is now bundled with the Hyperic distributions, and is no longer a separate download. Look for more information on monitoring GemFire and RabbitMQ in a future blog post.

While migrating, we also took the opportunity to move our code repository from subversion to git. To download the source from the git code repository go to http://git.springsource.org/hq. We also switched our build system from ant to maven. All of the Hyperic modules needed for development of custom plugins or features can now be downloaded from our maven repository at http://maven.hyperic.org/release.
Conclusion

I encourage you to download Hyperic 4.5 and/or check out the code. As always, community feedback through the forums is very much appreciated. We are looking forward to building on this easily extensible architecture that our conversion to Spring has provided. Stay tuned for more exciting enhancements!
comments powered by Disqus

translate:
翻译:

经过几个月的发展,我很自豪地宣布发布Hyperic 4.5。在这个版本中,我们将Hyperic从运行在JBoss上的EJB应用程序迁移到运行在Tomcat上的Spring web应用程序。详细的迁移步骤在我从EJB迁移Hyperic到Spring的案例研究中有介绍,最初出现在最近的SpringOne 2GX上。在这篇文章中,我想强调一些我最喜欢的关于转换的事情。
改进的可测试性
切换到Spring允许我们将现有的无状态会话ejb转换为具有自动连线依赖关系的pojo。这消除了相当多的静态JNDI查找代码,这些代码使得单元测试非常困难。Spring还大大简化了集成测试。在转换之前,我们进行了一些集成测试,每个测试都需要几分钟来引导一个EJB容器的近似值。这个过程很麻烦,而且容易出错。此外,测试经常使数据库处于不一致的状态,因此有必要添加数据库设置或删除代码,从而增加测试执行时间的额外开销,有时还会导致测试结果不一致。
转换之后,我们能够利用Spring的集成测试支持来测试转换后的ejb的新服务层及其底层dao。通过添加一些注释,我们能够在不到30秒的时间内引导整个应用程序上下文,并在测试结束时自动回滚的专用事务中运行每个测试方法。事实证明,这种支持非常有价值,使我们能够在开源代码库和企业代码库中分别将测试覆盖率快速提高18%和12%。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值