Author: adc Date: Sun Sep 4 00:24:26 2011 New Revision: 1164951 URL: http://svn.apache.org/viewvc?rev=1164951&view=rev Log: Some better names for the classes
Added: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/BaseFilterState.java - copied, changed from r1162111, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/BaseChannelState.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/IoFilterState.java - copied, changed from r1162111, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoChannelState.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/LinkStateFilter.java - copied, changed from r1162111, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/Link.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosedFilterState.java - copied, changed from r1162111, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosedChannelState.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosingFilterState.java - copied, changed from r1162111, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosingChannelState.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/FinishedFilterState.java - copied, changed from r1162111, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/FinishedChannelState.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/HandshakeFilterState.java - copied, changed from r1162111, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/HandshakeChannelState.java mina/sandbox/adc/ahc/mina3/src/test/java/org/apache/mina/link/ mina/sandbox/adc/ahc/mina3/src/test/java/org/apache/mina/link/UpStateTest.java Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/BaseChannelState.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoChannelState.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/StateMachineFilter.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/DownState.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/Link.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/UpState.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosedChannelState.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosingChannelState.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/FinishedChannelState.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/HandshakeChannelState.java mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/SslFilter.java Copied: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/BaseFilterState.java (from r1162111, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/BaseChannelState.java) URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/BaseFilterState.java?p2=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/BaseFilterState.java&p1=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/BaseChannelState.java&r1=1162111&r2=1164951&rev=1164951&view=diff ============================================================================== --- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/BaseChannelState.java (original) +++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/BaseFilterState.java Sun Sep 4 00:24:26 2011 @@ -16,20 +16,18 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.mina.core; +package org.apache.mina.core.state; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.mina.core.state.Event; - /** * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ -public abstract class BaseChannelState<R, P, S extends Enum, E extends Event> implements IoChannelState<R, P, S, E> +public abstract class BaseFilterState<R, P, S extends Enum, E extends Event> implements IoFilterState<R, P, S, E> { - private final static Logger LOGGER = LoggerFactory.getLogger(BaseChannelState.class); + private final static Logger LOGGER = LoggerFactory.getLogger(BaseFilterState.class); public void init() { Copied: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/IoFilterState.java (from r1162111, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoChannelState.java) URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/IoFilterState.java?p2=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/IoFilterState.java&p1=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoChannelState.java&r1=1162111&r2=1164951&rev=1164951&view=diff ============================================================================== --- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/IoChannelState.java (original) +++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/IoFilterState.java Sun Sep 4 00:24:26 2011 @@ -16,15 +16,12 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.mina.core; - -import org.apache.mina.core.state.Event; - +package org.apache.mina.core.state; /** * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ -public interface IoChannelState<U, D, S extends Enum, E extends Event> +public interface IoFilterState<U, D, S extends Enum, E extends Event> { void init(); Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/StateMachineFilter.java URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/StateMachineFilter.java?rev=1164951&r1=1164950&r2=1164951&view=diff ============================================================================== --- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/StateMachineFilter.java (original) +++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/core/state/StateMachineFilter.java Sun Sep 4 00:24:26 2011 @@ -31,7 +31,6 @@ import org.slf4j.LoggerFactory; import org.apache.mina.core.AbstractIoFilter; import org.apache.mina.core.EquipmentStack; -import org.apache.mina.core.IoChannelState; import org.apache.mina.core.api.IoEvent; import org.apache.mina.core.api.IoProperty; import org.apache.mina.core.api.IoPropertyScope; @@ -43,7 +42,7 @@ import org.apache.mina.core.api.IoProper public abstract class StateMachineFilter<U, D, S extends Enum, E extends Event> extends AbstractIoFilter { private final static Logger LOG = LoggerFactory.getLogger(StateMachineFilter.class); - private final Map<S, IoChannelState<U, D, S, E>> states = new HashMap<S, IoChannelState<U, D, S, E>>(); + private final Map<S, IoFilterState<U, D, S, E>> states = new HashMap<S, IoFilterState<U, D, S, E>>(); private final Queue<E> events = new LinkedList<E>(); private EquipmentStack equipmentStack; private volatile S state; @@ -71,17 +70,17 @@ public abstract class StateMachineFilter this.state = state; } - public final Map<S, IoChannelState<U, D, S, E>> getStates() + public final Map<S, IoFilterState<U, D, S, E>> getStates() { return Collections.unmodifiableMap(states); } - protected final void register(S state, IoChannelState<U, D, S, E> channelState) + protected final void register(S state, IoFilterState<U, D, S, E> filterState) { assert state != null; - assert channelState != null; + assert filterState != null; - IoChannelState previous = states.put(state, channelState); + IoFilterState previous = states.put(state, filterState); assert previous == null; } @@ -94,33 +93,33 @@ public abstract class StateMachineFilter { assert message != null; - IoChannelState<U, D, S, E> channelState = states.get(state); + IoFilterState<U, D, S, E> filterState = states.get(state); - equipmentStack.inject(channelState); - state = channelState.send(message); - equipmentStack.collect(channelState); + equipmentStack.inject(filterState); + state = filterState.send(message); + equipmentStack.collect(filterState); } public final void receive(U message) throws Exception { assert message != null; - IoChannelState<U, D, S, E> channelState = states.get(state); + IoFilterState<U, D, S, E> filterState = states.get(state); - equipmentStack.inject(channelState); - state = channelState.receive(message); - equipmentStack.collect(channelState); + equipmentStack.inject(filterState); + state = filterState.receive(message); + equipmentStack.collect(filterState); } public final void fire(E event) throws HandlerException { assert event != null; - IoChannelState<U, D, S, E> channelState = states.get(state); + IoFilterState<U, D, S, E> filterState = states.get(state); - equipmentStack.inject(channelState); - fireEvent(channelState, event); - equipmentStack.collect(channelState); + equipmentStack.inject(filterState); + fireEvent(filterState, event); + equipmentStack.collect(filterState); } protected final void queue(E event) @@ -129,7 +128,7 @@ public abstract class StateMachineFilter events.offer(event); } - private void fireEvent(IoChannelState<U, D, S, E> channelState, E event) throws HandlerException + private void fireEvent(IoFilterState<U, D, S, E> filterState, E event) throws HandlerException { assert state != null; assert event != null; Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/DownState.java URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/DownState.java?rev=1164951&r1=1164950&r2=1164951&view=diff ============================================================================== --- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/DownState.java (original) +++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/DownState.java Sun Sep 4 00:24:26 2011 @@ -23,16 +23,16 @@ import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.mina.core.BaseChannelState; import org.apache.mina.core.api.IoDown; import org.apache.mina.core.api.IoProperty; import org.apache.mina.core.api.IoPropertyScope; +import org.apache.mina.core.state.BaseFilterState; /** * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ -public class DownState extends BaseChannelState<Token, Token, State, TimeoutEvent> +public class DownState extends BaseFilterState<Token, Token, State, TimeoutEvent> { static final Logger LOG = LoggerFactory.getLogger(DownState.class); @IoProperty(scope = IoPropertyScope.SESSION) protected Set<LinkListener> listeners; @@ -44,7 +44,7 @@ public class DownState extends BaseChann public State send(Token message) throws Exception { LOG.error("Should not have been sent a token"); - throw new UnsupportedOperationException("Link state channel does not support message sending"); + throw new UnsupportedOperationException("Link state filter does not support message sending"); } @Override Copied: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/LinkStateFilter.java (from r1162111, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/Link.java) URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/LinkStateFilter.java?p2=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/LinkStateFilter.java&p1=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/Link.java&r1=1162111&r2=1164951&rev=1164951&view=diff ============================================================================== --- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/Link.java (original) +++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/LinkStateFilter.java Sun Sep 4 00:24:26 2011 @@ -33,20 +33,20 @@ import org.apache.mina.core.state.StateM /** * A link connectivity protocol. * <p/> - * P. LeMahieu and J. Bruck, "A Consistent History Link Connectivity + * P. LeMahieu and J. Bruck, "A Consistent History LinkStateFilter Connectivity * Protocol," Proc. 17th ACM Symp. Principles of Distributed * Computing, p. 309, July 1998. * * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ -public class Link extends StateMachineFilter<Token, Token, State, TimeoutEvent> implements IoUp<Token> +public class LinkStateFilter extends StateMachineFilter<Token, Token, State, TimeoutEvent> implements IoUp<Token> { - static final Logger LOG = LoggerFactory.getLogger(Link.class); + static final Logger LOG = LoggerFactory.getLogger(LinkStateFilter.class); @IoProperty protected IoDown<Token> child; @IoProperty protected int numTokens; @IoProperty(scope = IoPropertyScope.SESSION) protected Set<LinkListener> listeners; - public Link() + public LinkStateFilter() { register(State.UP, new UpState()); register(State.DOWN, new DownState()); Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/UpState.java URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/UpState.java?rev=1164951&r1=1164950&r2=1164951&view=diff ============================================================================== --- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/UpState.java (original) +++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/link/UpState.java Sun Sep 4 00:24:26 2011 @@ -23,17 +23,17 @@ import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.mina.core.BaseChannelState; import org.apache.mina.core.api.IoDown; import org.apache.mina.core.api.IoEvent; import org.apache.mina.core.api.IoProperty; import org.apache.mina.core.api.IoPropertyScope; +import org.apache.mina.core.state.BaseFilterState; /** * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ -public class UpState extends BaseChannelState<Token, Token, State, TimeoutEvent> +public class UpState extends BaseFilterState<Token, Token, State, TimeoutEvent> { static final Logger LOG = LoggerFactory.getLogger(UpState.class); @IoProperty(scope = IoPropertyScope.SESSION) protected Set<LinkListener> listeners; @@ -44,7 +44,7 @@ public class UpState extends BaseChannel public State send(Token message) throws Exception { LOG.error("Should not have been sent a token"); - throw new UnsupportedOperationException("Link state channel does not support message sending"); + throw new UnsupportedOperationException("Link state filter does not support message sending"); } @Override Copied: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosedFilterState.java (from r1162111, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosedChannelState.java) URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosedFilterState.java?p2=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosedFilterState.java&p1=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosedChannelState.java&r1=1162111&r2=1164951&rev=1164951&view=diff ============================================================================== --- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosedChannelState.java (original) +++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosedFilterState.java Sun Sep 4 00:24:26 2011 @@ -18,14 +18,14 @@ */ package org.apache.mina.ssl; -import org.apache.mina.core.IoChannelState; +import org.apache.mina.core.state.IoFilterState; import org.apache.mina.nio.IoByteBuffer; /** * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ -public class ClosedChannelState implements IoChannelState<IoByteBuffer, IoByteBuffer, SslStates, SslEvent> +public class ClosedFilterState implements IoFilterState<IoByteBuffer, IoByteBuffer, SslStates, SslEvent> { public void init() { Copied: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosingFilterState.java (from r1162111, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosingChannelState.java) URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosingFilterState.java?p2=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosingFilterState.java&p1=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosingChannelState.java&r1=1162111&r2=1164951&rev=1164951&view=diff ============================================================================== --- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosingChannelState.java (original) +++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/ClosingFilterState.java Sun Sep 4 00:24:26 2011 @@ -18,14 +18,14 @@ */ package org.apache.mina.ssl; -import org.apache.mina.core.IoChannelState; +import org.apache.mina.core.state.IoFilterState; import org.apache.mina.nio.IoByteBuffer; /** * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ -public class ClosingChannelState implements IoChannelState<IoByteBuffer, IoByteBuffer, SslStates, SslEvent> +public class ClosingFilterState implements IoFilterState<IoByteBuffer, IoByteBuffer, SslStates, SslEvent> { public void init() { Copied: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/FinishedFilterState.java (from r1162111, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/FinishedChannelState.java) URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/FinishedFilterState.java?p2=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/FinishedFilterState.java&p1=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/FinishedChannelState.java&r1=1162111&r2=1164951&rev=1164951&view=diff ============================================================================== --- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/FinishedChannelState.java (original) +++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/FinishedFilterState.java Sun Sep 4 00:24:26 2011 @@ -24,18 +24,18 @@ import java.nio.ByteBuffer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.mina.core.BaseChannelState; import org.apache.mina.core.api.IoProperty; import org.apache.mina.core.api.IoPropertyScope; +import org.apache.mina.core.state.BaseFilterState; import org.apache.mina.nio.IoByteBuffer; /** * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ -public class FinishedChannelState extends BaseChannelState<IoByteBuffer, IoByteBuffer, SslStates, SslEvent> +public class FinishedFilterState extends BaseFilterState<IoByteBuffer, IoByteBuffer, SslStates, SslEvent> { - private final static Logger LOGGER = LoggerFactory.getLogger(FinishedChannelState.class); + private final static Logger LOGGER = LoggerFactory.getLogger(FinishedFilterState.class); private ByteBuffer byteBuffer; private SSLEngine engine; Copied: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/HandshakeFilterState.java (from r1162111, mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/HandshakeChannelState.java) URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/HandshakeFilterState.java?p2=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/HandshakeFilterState.java&p1=mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/HandshakeChannelState.java&r1=1162111&r2=1164951&rev=1164951&view=diff ============================================================================== --- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/HandshakeChannelState.java (original) +++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/HandshakeFilterState.java Sun Sep 4 00:24:26 2011 @@ -24,22 +24,22 @@ import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.mina.core.BaseChannelState; import org.apache.mina.core.IoBufferFactory; import org.apache.mina.core.api.IoDown; import org.apache.mina.core.api.IoEvent; import org.apache.mina.core.api.IoProperty; import org.apache.mina.core.api.IoPropertyScope; import org.apache.mina.core.api.IoUp; +import org.apache.mina.core.state.BaseFilterState; import org.apache.mina.nio.IoByteBuffer; /** * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ -public class HandshakeChannelState extends BaseChannelState<IoByteBuffer, IoByteBuffer, SslStates, SslEvent> +public class HandshakeFilterState extends BaseFilterState<IoByteBuffer, IoByteBuffer, SslStates, SslEvent> { - private final static Logger LOGGER = LoggerFactory.getLogger(HandshakeChannelState.class); + private final static Logger LOGGER = LoggerFactory.getLogger(HandshakeFilterState.class); @IoProperty(scope = IoPropertyScope.GLOBAL) private IoBufferFactory<IoByteBuffer> factory; @IoProperty private SSLEngine engine; @IoProperty(scope = IoPropertyScope.SESSION) private Set<SslListener> listeners; Modified: mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/SslFilter.java URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/SslFilter.java?rev=1164951&r1=1164950&r2=1164951&view=diff ============================================================================== --- mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/SslFilter.java (original) +++ mina/sandbox/adc/ahc/mina3/src/main/java/org/apache/mina/ssl/SslFilter.java Sun Sep 4 00:24:26 2011 @@ -39,10 +39,10 @@ public class SslFilter extends StateMach public SslFilter() { - register(SslStates.HANDSHAKE, new HandshakeChannelState()); - register(SslStates.FINISHED, new FinishedChannelState()); - register(SslStates.CLOSING, new ClosingChannelState()); - register(SslStates.CLOSED, new ClosedChannelState()); + register(SslStates.HANDSHAKE, new HandshakeFilterState()); + register(SslStates.FINISHED, new FinishedFilterState()); + register(SslStates.CLOSING, new ClosingFilterState()); + register(SslStates.CLOSED, new ClosedFilterState()); } @Override Added: mina/sandbox/adc/ahc/mina3/src/test/java/org/apache/mina/link/UpStateTest.java URL: http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/mina3/src/test/java/org/apache/mina/link/UpStateTest.java?rev=1164951&view=auto ============================================================================== --- mina/sandbox/adc/ahc/mina3/src/test/java/org/apache/mina/link/UpStateTest.java (added) +++ mina/sandbox/adc/ahc/mina3/src/test/java/org/apache/mina/link/UpStateTest.java Sun Sep 4 00:24:26 2011 @@ -0,0 +1,80 @@ +/** + * 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. + */ +package org.apache.mina.link; + +import java.util.HashSet; +import java.util.Set; + +import static org.apache.ahc.test.Utils.inject; +import org.junit.After; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import org.junit.Test; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import org.apache.mina.core.api.IoDown; + + +/** + * @author <a href="http://mina.apache.org">Apache MINA Project</a> + */ +public class UpStateTest +{ + protected final static Set<LinkListener> LISTENERS = new HashSet<LinkListener>(); + + @Test + public void testFirstTimeout() throws Exception + { + IoDown<Token> down = mock(IoDown.class); + UpState filter = new UpState(); + inject(filter, "listeners", LISTENERS); + inject(filter, "numTokens", 2); + inject(filter, "child", down); + + LinkListener listener = mock(LinkListener.class); + LISTENERS.add(listener); + + assertEquals(State.DOWN, filter.handle(new TimeoutEvent())); + + verify(listener).down(); + verify(down).send(any(Token.class)); + } + + @Test + public void testUnsupportedOperation() throws Exception + { + UpState filter = new UpState(); + try + { + filter.send(new Token()); + fail("The send() method is unsupported"); + } + catch (UnsupportedOperationException ignore) + { + } + } + + @After + public void after() + { + LISTENERS.clear(); + } +}