Author: chris.laprun(a)jboss.com
Date: 2011-10-17 15:47:23 -0400 (Mon, 17 Oct 2011)
New Revision: 7754
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/InMemoryConsumerRegistry.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistryTestCase.java
Log:
- Try to activate consumers when we create them if they are marked as active
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java 2011-10-17
18:09:59 UTC (rev 7753)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java 2011-10-17
19:47:23 UTC (rev 7754)
@@ -200,7 +200,7 @@
// make sure we set the registry after loading from DB since registry is not
persisted.
// producerInfo.setRegistry(this);
- final WSRPConsumerImpl consumer = new WSRPConsumerImpl(producerInfo);
+ final WSRPConsumerImpl consumer = createAndActivateIfNeeded(producerInfo);
// cache consumer
consumers.putConsumer(producerInfo.getId(), consumer);
@@ -208,6 +208,18 @@
return consumer;
}
+ private WSRPConsumerImpl createAndActivateIfNeeded(ProducerInfo producerInfo)
+ {
+ final WSRPConsumerImpl consumer = new WSRPConsumerImpl(producerInfo);
+
+ // try to activate consumer if it's marked as active and isn't yet
+ if (producerInfo.isActive() && !consumer.isActive())
+ {
+ activateConsumer(consumer);
+ }
+ return consumer;
+ }
+
public void activateConsumerWith(String id) throws ConsumerException
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer
identifier", "Activating a Consumer");
@@ -505,7 +517,7 @@
while (infosFromStorage.hasNext())
{
ProducerInfo info = infosFromStorage.next();
- consumers.put(info.getId(), createConsumerFrom(info));
+ consumers.put(info.getId(), createAndActivateIfNeeded(info));
}
lastModified = System.currentTimeMillis();
setInvalidated(false);
@@ -528,7 +540,7 @@
ProducerInfo info = loadProducerInfo(id);
if (info != null)
{
- consumer = createConsumerFrom(info);
+ consumer = createAndActivateIfNeeded(info);
}
}
return consumer;
@@ -584,7 +596,7 @@
{
info = loadProducerInfo(id);
}
- consumers.put(id, createConsumerFrom(info));
+ consumers.put(id, createAndActivateIfNeeded(info));
}
}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/InMemoryConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/InMemoryConsumerRegistry.java 2011-10-17
18:09:59 UTC (rev 7753)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/InMemoryConsumerRegistry.java 2011-10-17
19:47:23 UTC (rev 7754)
@@ -81,6 +81,7 @@
{
// generate a UUID for ProducerInfo
info.setKey(UUID.randomUUID().toString());
+ keysToIds.put(info.getKey(), info.getId());
}
public void delete(ProducerInfo info)
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java 2011-10-17
18:09:59 UTC (rev 7753)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java 2011-10-17
19:47:23 UTC (rev 7754)
@@ -150,7 +150,7 @@
assertEquals(1, registry.getConfiguredConsumerNumber());
}
- public void testStoppingShouldntStartConsumers() throws Exception
+ public void testStoppingShouldNotStartConsumers() throws Exception
{
// fake marking consumer as active in persistence
ProducerInfo info = Mockito.mock(ProducerInfo.class);
@@ -159,9 +159,14 @@
Mockito.stub(info.getKey()).toReturn("fooKey");
EndpointConfigurationInfo endpoint =
Mockito.mock(EndpointConfigurationInfo.class);
Mockito.stub(info.getEndpointConfigurationInfo()).toReturn(endpoint);
+ registry.save(info, "Couldn't save ProducerInfo");
+ WSRPConsumer original = registry.createConsumerFrom(info);
+
+ // since consumer is supposed to be active, the registry will attempt to start it:
+ assertEquals(original,
registry.getFederatingPortletInvoker().getFederatedInvoker("foo").getPortletInvoker());
+
// create a consumer to spy from
- WSRPConsumer original = registry.createConsumerFrom(info);
WSRPConsumer consumer = Mockito.spy(original);
// force re-init of registry from "persistence" to ensure that the spy
registry actually uses our spy consumer
@@ -173,14 +178,10 @@
assertTrue(foo.getProducerInfo().isActive());
assertEquals(consumer, foo);
- // start consumer and check that it's properly added to the
FederatingPortletInvoker
- registrySpy.activateConsumer(foo);
- assertEquals(consumer,
registrySpy.getFederatingPortletInvoker().getFederatedInvoker("foo").getPortletInvoker());
-
- // stop the consumer and then the registry and check that consumer.start has only
been called once
+ // stop the consumer and then the registry and check that consumer.start hasn't
been called
consumer.stop();
registrySpy.stop();
- Mockito.verify(consumer, Mockito.times(1)).start();
+ Mockito.verify(consumer, Mockito.times(0)).start();
// check that consumer is not known by the FederatingPortletInvoker anymore
assertEquals(null,
registrySpy.getFederatingPortletInvoker().getFederatedInvoker("foo"));
Modified:
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistryTestCase.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistryTestCase.java 2011-10-17
18:09:59 UTC (rev 7753)
+++
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistryTestCase.java 2011-10-17
19:47:23 UTC (rev 7754)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * Copyright 2011, Red Hat Middleware, LLC, and individual
* contributors as indicated by the @authors tag. See the
* copyright.txt in the distribution for a full listing of
* individual contributors.
@@ -88,7 +88,7 @@
}
@Override
- public void testStoppingShouldntStartConsumers() throws Exception
+ public void testStoppingShouldNotStartConsumers() throws Exception
{
// override to bypass this test as I couldn't find a way to make it work
properly (i.e. how to inject a Mock
// into the registry to check that start is only called once)