Author: davsclaus
Date: Thu Aug 25 07:00:51 2011
New Revision: 1161417
URL: http://svn.apache.org/viewvc?rev=1161417&view=rev
Log:
CAMEL-2472: Use slf4j for logging. Fixed the dependency in pom.xml. Generate
JAR as osgi bundle. Dont use camel-core-test for unit testing.
Added:
camel/trunk/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperManagedEndpointTest.java
- copied, changed from r1161397,
camel/trunk/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperEndpointTest.java
Removed:
camel/trunk/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperEndpointTest.java
Modified:
camel/trunk/components/camel-zookeeper/pom.xml
camel/trunk/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ConnectionHolder.java
camel/trunk/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConnectionManager.java
camel/trunk/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperOperation.java
Modified: camel/trunk/components/camel-zookeeper/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-zookeeper/pom.xml?rev=1161417&r1=1161416&r2=1161417&view=diff
==============================================================================
--- camel/trunk/components/camel-zookeeper/pom.xml (original)
+++ camel/trunk/components/camel-zookeeper/pom.xml Thu Aug 25 07:00:51 2011
@@ -1,51 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project>
-<parent>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
<artifactId>components</artifactId>
<groupId>org.apache.camel</groupId>
<version>2.9-SNAPSHOT</version>
</parent>
- <modelVersion>4.0.0</modelVersion>
+
<artifactId>camel-zookeeper</artifactId>
-
+ <packaging>bundle</packaging>
<name>Camel :: Zookeeper</name>
<description>Camel Zookeeper Support</description>
-
+
<properties>
<camel.osgi.export.pkg>org.apache.camel.component.zookeeper.*</camel.osgi.export.pkg>
</properties>
<dependencies>
- <dependency>
- <groupId>org.apache.zookeeper</groupId>
- <artifactId>zookeeper</artifactId>
- </dependency>
+
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core</artifactId>
- <version>${pom.version}</version>
- <scope>test</scope>
- <classifier>tests</classifier>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-spring</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </dependency>
+ <groupId>org.apache.zookeeper</groupId>
+ <artifactId>zookeeper</artifactId>
+ </dependency>
+
+ <!-- testing -->
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-test</artifactId>
+ <artifactId>camel-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -54,10 +58,11 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
+
</dependencies>
</project>
Modified:
camel/trunk/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ConnectionHolder.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ConnectionHolder.java?rev=1161417&r1=1161416&r2=1161417&view=diff
==============================================================================
---
camel/trunk/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ConnectionHolder.java
(original)
+++
camel/trunk/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ConnectionHolder.java
Thu Aug 25 07:00:51 2011
@@ -18,16 +18,14 @@ package org.apache.camel.component.zooke
import java.util.concurrent.CountDownLatch;
-import static java.lang.String.format;
-
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.util.ObjectHelper;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooKeeper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* <code>ConnectionHolder</code> watches for Connection based events from
@@ -35,8 +33,7 @@ import org.apache.zookeeper.ZooKeeper;
* established.
*/
public class ConnectionHolder implements Watcher {
-
- private static final transient Log LOG =
LogFactory.getLog(ConnectionHolder.class);
+ private static final transient Logger LOG =
LoggerFactory.getLogger(ConnectionHolder.class);
private CountDownLatch connectionLatch = new CountDownLatch(1);
@@ -74,7 +71,7 @@ public class ConnectionHolder implements
public void awaitConnection() {
if (LOG.isDebugEnabled()) {
- LOG.debug(format("Awaiting Connection event from Zookeeper cluster
%s", configuration.getConnectString()));
+ LOG.debug("Awaiting Connection event from Zookeeper cluster {}",
configuration.getConnectString());
}
try {
connectionLatch.await();
@@ -94,10 +91,10 @@ public class ConnectionHolder implements
try {
zookeeper.close();
if (LOG.isDebugEnabled()) {
- LOG.debug(format("Shutting down connection to Zookeeper
cluster %s", configuration.getConnectString()));
+ LOG.debug("Shutting down connection to Zookeeper cluster {}",
configuration.getConnectString());
}
} catch (InterruptedException e) {
- LOG.error("Error closing zookeeper connection.", e);
+ LOG.warn("Error closing zookeeper connection " +
configuration.getConnectString() + ". This exception will be ignored.", e);
}
}
}
Modified:
camel/trunk/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConnectionManager.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConnectionManager.java?rev=1161417&r1=1161416&r2=1161417&view=diff
==============================================================================
---
camel/trunk/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConnectionManager.java
(original)
+++
camel/trunk/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConnectionManager.java
Thu Aug 25 07:00:51 2011
@@ -16,9 +16,9 @@
*/
package org.apache.camel.component.zookeeper;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.zookeeper.ZooKeeper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* <code>ZookeeperConnectionManager</code> is a simple class to manage
@@ -26,7 +26,7 @@ import org.apache.zookeeper.ZooKeeper;
*/
public class ZooKeeperConnectionManager {
- private static final Log LOG =
LogFactory.getLog(ZooKeeperConnectionManager.class);
+ private static final Logger LOG =
LoggerFactory.getLogger(ZooKeeperConnectionManager.class);
private ZookeeperConnectionStrategy strategy;
@@ -50,9 +50,7 @@ public class ZooKeeperConnectionManager
public DefaultZookeeperConnectionStrategy(ZooKeeperEndpoint endpoint) {
this.configuration = endpoint.getConfiguration();
- if (LOG.isDebugEnabled()) {
- LOG.debug(String.format("Creating connection with static
configuration of %s", configuration));
- }
+ LOG.debug("Creating connection with static configuration of {}",
configuration);
holder = new ConnectionHolder(configuration);
}
Modified:
camel/trunk/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperOperation.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperOperation.java?rev=1161417&r1=1161416&r2=1161417&view=diff
==============================================================================
---
camel/trunk/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperOperation.java
(original)
+++
camel/trunk/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/operations/ZooKeeperOperation.java
Thu Aug 25 07:00:51 2011
@@ -22,9 +22,9 @@ import java.util.concurrent.ExecutionExc
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.zookeeper.ZooKeeper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* <code>ZooKeeperOperation</code> is the base class for wrapping various
@@ -34,7 +34,7 @@ import org.apache.zookeeper.ZooKeeper;
@SuppressWarnings("rawtypes")
public abstract class ZooKeeperOperation<ResultType> {
- protected static final transient Log LOG =
LogFactory.getLog(ZooKeeperOperation.class);
+ protected static final transient Logger LOG =
LoggerFactory.getLogger(ZooKeeperOperation.class);
protected static final Class[] CONSTRUCTOR_ARGS = {ZooKeeper.class,
String.class};
@@ -63,8 +63,6 @@ public abstract class ZooKeeperOperation
/**
* Gets the result of this zookeeper operation, i.e. some data and the
* associated node stats
- *
- * @return
*/
public abstract OperationResult<ResultType> getResult();
@@ -75,7 +73,8 @@ public abstract class ZooKeeperOperation
}
public OperationResult<ResultType> get(long timeout, TimeUnit unit) throws
InterruptedException, ExecutionException, TimeoutException {
- return get(); // TODO ; perhaps set a timer here ....
+ // TODO perhaps set a timer here
+ return get();
}
public boolean cancel(boolean mayInterruptIfRunning) {
@@ -104,8 +103,7 @@ public abstract class ZooKeeperOperation
return producesExchange;
}
-
- // TODO: slightly different to a clone as it uses the constructor
+ // TODO slightly different to a clone as it uses the constructor
public ZooKeeperOperation createCopy() throws Exception {
return getClass().getConstructor(CONSTRUCTOR_ARGS).newInstance(new
Object[] {connection, node});
}
Copied:
camel/trunk/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperManagedEndpointTest.java
(from r1161397,
camel/trunk/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperEndpointTest.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperManagedEndpointTest.java?p2=camel/trunk/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperManagedEndpointTest.java&p1=camel/trunk/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperEndpointTest.java&r1=1161397&r2=1161417&rev=1161417&view=diff
==============================================================================
---
camel/trunk/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperEndpointTest.java
(original)
+++
camel/trunk/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperManagedEndpointTest.java
Thu Aug 25 07:00:51 2011
@@ -18,43 +18,53 @@ package org.apache.camel.component.zooke
import java.util.ArrayList;
import java.util.Set;
-
import javax.management.Attribute;
+import javax.management.MBeanServer;
import javax.management.ObjectName;
+import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import
org.apache.camel.component.zookeeper.ZooKeeperTestSupport.TestZookeeperClient;
-import
org.apache.camel.component.zookeeper.ZooKeeperTestSupport.TestZookeeperServer;
-import org.apache.camel.management.JmxInstrumentationUsingDefaultsTest;
-import org.apache.zookeeper.ZooKeeper;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.management.DefaultManagementNamingStrategy;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
import org.springframework.jmx.support.JmxUtils;
@SuppressWarnings("all")
-public class ZooKeeperEndpointTest extends JmxInstrumentationUsingDefaultsTest
{
-
- private static int teardownAfter;
+public class ZooKeeperManagedEndpointTest extends CamelTestSupport {
@Override
- protected void setUp() throws Exception {
- if (teardownAfter == 0) {
- ZooKeeperTestSupport.setupTestServer();
- }
+ public void setUp() throws Exception {
+ ZooKeeperTestSupport.setupTestServer();
super.setUp();
}
@Override
- protected void tearDown() throws Exception {
+ public void tearDown() throws Exception {
super.tearDown();
- if (++teardownAfter == 3) {
- ZooKeeperTestSupport.shutdownServer();
- }
+ ZooKeeperTestSupport.shutdownServer();
+ }
+
+ @Override
+ protected boolean useJmx() {
+ return true;
+ }
+
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = new DefaultCamelContext();
+ DefaultManagementNamingStrategy naming =
(DefaultManagementNamingStrategy)
context.getManagementStrategy().getManagementNamingStrategy();
+ naming.setHostName("localhost");
+ naming.setDomainName("org.apache.camel");
+ return context;
+ }
+
+ protected MBeanServer getMBeanServer() {
+ return
context.getManagementStrategy().getManagementAgent().getMBeanServer();
}
- public synchronized void testEnpointConfigurationCanBeSetViaJMX() throws
Exception {
- Set s = mbsc.queryNames(new ObjectName(domainName +
":type=endpoints,name=\"zoo:*\",*"), null);
+ @Test
+ public void testEnpointConfigurationCanBeSetViaJMX() throws Exception {
+ Set s = getMBeanServer().queryNames(new
ObjectName("org.apache.camel:type=endpoints,name=\"zoo:*\",*"), null);
assertEquals("Could not find zookeper endpoint: " + s, 1, s.size());
ObjectName zepName = new ArrayList<ObjectName>(s).get(0);
@@ -66,38 +76,29 @@ public class ZooKeeperEndpointTest exten
verifyManagedAttribute(zepName, "Timeout", 12345);
verifyManagedAttribute(zepName, "Backoff", 12345L);
- mbsc.invoke(zepName, "clearServers", null,
JmxUtils.getMethodSignature(ZooKeeperEndpoint.class.getMethod("clearServers",
null)));
- mbsc.invoke(zepName, "addServer", new Object[] {"someserver:12345"},
-
JmxUtils.getMethodSignature(ZooKeeperEndpoint.class.getMethod("addServer", new
Class[] {String.class})));
-
+ getMBeanServer().invoke(zepName, "clearServers", null,
JmxUtils.getMethodSignature(ZooKeeperEndpoint.class.getMethod("clearServers",
null)));
+ getMBeanServer().invoke(zepName, "addServer", new
Object[]{"someserver:12345"},
+
JmxUtils.getMethodSignature(ZooKeeperEndpoint.class.getMethod("addServer", new
Class[]{String.class})));
}
private void verifyManagedAttribute(ObjectName zepName, String
attributeName, String attributeValue) throws Exception {
- mbsc.setAttribute(zepName, new Attribute(attributeName,
attributeValue));
- assertEquals(attributeValue, mbsc.getAttribute(zepName,
attributeName));
+ getMBeanServer().setAttribute(zepName, new Attribute(attributeName,
attributeValue));
+ assertEquals(attributeValue, getMBeanServer().getAttribute(zepName,
attributeName));
}
private void verifyManagedAttribute(ObjectName zepName, String
attributeName, Integer attributeValue) throws Exception {
- mbsc.setAttribute(zepName, new Attribute(attributeName,
attributeValue));
- assertEquals(attributeValue, mbsc.getAttribute(zepName,
attributeName));
+ getMBeanServer().setAttribute(zepName, new Attribute(attributeName,
attributeValue));
+ assertEquals(attributeValue, getMBeanServer().getAttribute(zepName,
attributeName));
}
private void verifyManagedAttribute(ObjectName zepName, String
attributeName, Boolean attributeValue) throws Exception {
- mbsc.setAttribute(zepName, new Attribute(attributeName,
attributeValue));
- assertEquals(attributeValue, mbsc.getAttribute(zepName,
attributeName));
+ getMBeanServer().setAttribute(zepName, new Attribute(attributeName,
attributeValue));
+ assertEquals(attributeValue, getMBeanServer().getAttribute(zepName,
attributeName));
}
private void verifyManagedAttribute(ObjectName zepName, String
attributeName, Long attributeValue) throws Exception {
- mbsc.setAttribute(zepName, new Attribute(attributeName,
attributeValue));
- assertEquals(attributeValue, mbsc.getAttribute(zepName,
attributeName));
- }
-
- @Override
- public void testCounters() throws Exception {
- }
-
- @Override
- public void testMBeansRegistered() throws Exception {
+ getMBeanServer().setAttribute(zepName, new Attribute(attributeName,
attributeValue));
+ assertEquals(attributeValue, getMBeanServer().getAttribute(zepName,
attributeName));
}
protected RouteBuilder createRouteBuilder() {