Skip to content

Commit

Permalink
fix bug when you try to subscribe 2x
Browse files Browse the repository at this point in the history
  • Loading branch information
peter royal committed Feb 5, 2010
1 parent 1c7790d commit 83e1eaa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
13 changes: 6 additions & 7 deletions src/main/java/org/fotap/heysync/ClassCreatingClassloader.java
Expand Up @@ -22,8 +22,7 @@ <T> T publisherFor(Class<T> type, Map<Method, ? extends Publisher<?>> publishers
}

private <T> Object[] publisherArguments(PublisherCreator<T> publisherCreator,
Map<Method, ? extends Publisher<?>> publishers)
{
Map<Method, ? extends Publisher<?>> publishers) {
List<Publisher<?>> arguments = new ArrayList<Publisher<?>>();
for (Method method : publisherCreator.methods()) {
arguments.add(publishers.get(method));
Expand All @@ -50,7 +49,7 @@ private <T> Class<? extends T> defineClass(ClassCreator<T> creator) {

private <R> Class<? extends Callback<R>> loadCallbackClass(Method method) {
Type type = callbackTypeFor(method);
Class<?> callbackClass = findLoadedClass(type.getInternalName());
Class<?> callbackClass = findLoadedClass(type.getClassName());
if (null != callbackClass) {
return Cast.as(callbackClass);
}
Expand All @@ -59,10 +58,10 @@ private <R> Class<? extends Callback<R>> loadCallbackClass(Method method) {

private Type callbackTypeFor(Method method) {
StringBuilder builder = new StringBuilder()
.append("L")
.append(Type.getInternalName(method.getDeclaringClass()))
.append("$Callback$")
.append(method.getName());
.append("L")
.append(Type.getInternalName(method.getDeclaringClass()))
.append("$Callback$")
.append(method.getName());

for (Class<?> type : method.getParameterTypes()) {
builder.append("$").append(type.getName().replace('.', '$'));
Expand Down
17 changes: 13 additions & 4 deletions src/test/java/org/fotap/heysync/ProtocolTest.java
Expand Up @@ -31,6 +31,15 @@ public void shouldSendAsyncMessage() {
verify(receiver).eatCheese("cheddar");
}

@Test
public void shouldHandleMultipleSubscribers() {
FiberStub executor = new FiberStub();

Protocol<Mouse> protocol = Protocol.create(Mouse.class);
protocol.subscribe(executor, mock(Mouse.class, "one"));
protocol.subscribe(executor, mock(Mouse.class, "two"));
}

@Test
public void shouldSendAsyncSignal() {
FiberStub executor = new FiberStub();
Expand All @@ -49,7 +58,7 @@ public void shouldSendAsyncSignal() {
public void shouldFailWhenTryingToGetDispatcherForNotAtAsynchronousInterface() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Cannot create a protocol for " + Collection.class.getName() + ". It must be an interface that is marked with the " + Asynchronous.class
.getName() + " annotation");
.getName() + " annotation");

Protocol.create(Collection.class);
}
Expand All @@ -58,7 +67,7 @@ public void shouldFailWhenTryingToGetDispatcherForNotAtAsynchronousInterface() {
public void shouldFailWhenTryingToGetDispatcherForClass() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Cannot create a protocol for " + Object.class.getName() + ". It must be an interface that is marked with the " + Asynchronous.class
.getName() + " annotation");
.getName() + " annotation");

Protocol.create(Object.class);
}
Expand All @@ -73,7 +82,7 @@ public void shouldGetChannelForMethod() throws NoSuchMethodException {
public void shouldFailWhenSpecifyingInvalidParameterType() throws NoSuchMethodException {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage(
"Specified parameter type java.lang.Object is not what the method requires: public abstract void org.fotap.heysync.Mouse.eatCheese(java.lang.String)");
"Specified parameter type java.lang.Object is not what the method requires: public abstract void org.fotap.heysync.Mouse.eatCheese(java.lang.String)");

Protocol<Mouse> protocol = Protocol.create(Mouse.class);
assertNotNull(protocol.channelFor(Mouse.class.getMethod("eatCheese", String.class), Object.class));
Expand All @@ -83,7 +92,7 @@ public void shouldFailWhenSpecifyingInvalidParameterType() throws NoSuchMethodEx
public void shouldFailWhenTryingToGetChannelForInvalidMethod() throws NoSuchMethodException {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage(
"public java.lang.String java.lang.Object.toString() is not a method on org.fotap.heysync.Mouse");
"public java.lang.String java.lang.Object.toString() is not a method on org.fotap.heysync.Mouse");

Protocol<Mouse> protocol = Protocol.create(Mouse.class);
protocol.channelFor(Object.class.getMethod("toString"), Object.class);
Expand Down

0 comments on commit 83e1eaa

Please sign in to comment.