From e20c35bf50bb3af99104325a83372a9a157b36c8 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Thu, 6 Dec 2012 15:01:40 +0100 Subject: [PATCH] Fix FakeChannelSink so events are put into the queue in the right order (BEFORE running event handlers, not after). --- .../com/google/bitcoin/core/FakeChannelSink.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/core/src/test/java/com/google/bitcoin/core/FakeChannelSink.java b/core/src/test/java/com/google/bitcoin/core/FakeChannelSink.java index 3340350d..9d545a80 100644 --- a/core/src/test/java/com/google/bitcoin/core/FakeChannelSink.java +++ b/core/src/test/java/com/google/bitcoin/core/FakeChannelSink.java @@ -1,18 +1,19 @@ package com.google.bitcoin.core; -import static org.jboss.netty.channel.Channels.fireChannelConnected; - import org.jboss.netty.channel.*; +import static org.jboss.netty.channel.Channels.fireChannelConnected; + public class FakeChannelSink extends AbstractChannelSink { - public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) - throws Exception { + public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) throws Exception { if (e instanceof ChannelStateEvent) { ChannelStateEvent event = (ChannelStateEvent) e; - FakeChannel channel = - (FakeChannel) event.getChannel(); + FakeChannel channel = (FakeChannel) event.getChannel(); + boolean offered = channel.events.offer(event); + assert offered; + ChannelFuture future = event.getFuture(); ChannelState state = event.getState(); Object value = event.getValue(); @@ -42,8 +43,6 @@ public class FakeChannelSink extends AbstractChannelSink { future.setSuccess(); break; } - boolean offered = channel.events.offer(event); - assert offered; } else if (e instanceof MessageEvent) { MessageEvent event = (MessageEvent) e; FakeChannel channel = (FakeChannel) event.getChannel();