Package com.starlight.intrepid

Examples of com.starlight.intrepid.ChannelAcceptor


  public void testClear() throws Exception {
    PluggableChannelAcceptor main_acceptor = new PluggableChannelAcceptor();

    // Add a single acceptor that takes anything
    ChannelAcceptor accepting_acceptor = EasyMock.createMock( ChannelAcceptor.class );
    EasyMock.replay( accepting_acceptor );
    main_acceptor.addDelegate( accepting_acceptor );

    // Clear delegates
    main_acceptor.removeAll();
View Full Code Here


  public void testSingleAcceptor() throws Exception {
    PluggableChannelAcceptor main_acceptor = new PluggableChannelAcceptor();

    // Add a single acceptor that takes anything
    ChannelAcceptor accepting_acceptor = EasyMock.createMock( ChannelAcceptor.class );
    accepting_acceptor.newChannel( null, null, "test" );
    EasyMock.replay( accepting_acceptor );
    main_acceptor.addDelegate( accepting_acceptor );

    try {
      main_acceptor.newChannel( null, null, "test" );
    }
    catch( ChannelRejectedException ex ) {
      ex.printStackTrace();
      fail( "Shouldn't have thrown exception" );
    }

    EasyMock.verify( accepting_acceptor );


    // Clear
    main_acceptor.removeAll();


    // Add acceptor again to the front this time (should be equivalent)
    EasyMock.reset( accepting_acceptor );
    accepting_acceptor.newChannel( null, null, "test 2" );
    EasyMock.replay( accepting_acceptor );
    main_acceptor.addDelegateToFront( accepting_acceptor );

    try {
      main_acceptor.newChannel( null, null, "test 2" );
View Full Code Here

  public void testMultipleAcceptors() throws Exception {
    PluggableChannelAcceptor main_acceptor = new PluggableChannelAcceptor();

    // Acceptor mocks
    ChannelAcceptor acceptor1 = EasyMock.createMock( ChannelAcceptor.class );
    ChannelAcceptor acceptor2 = EasyMock.createMock( ChannelAcceptor.class );
    ChannelAcceptor acceptor3 = EasyMock.createMock( ChannelAcceptor.class );

    // Scenario 1:
    //  1) Add acceptor 1, deny connection
    acceptor1.newChannel( null, null, "A" );
    EasyMock.expectLastCall().andThrow( new ChannelRejectedException() );
    EasyMock.replay( acceptor1, acceptor2, acceptor3 );

    main_acceptor.addDelegate( acceptor1 );

    try {
      main_acceptor.newChannel( null, null, "A" );
      fail( "Shouldn't have worked" );
    }
    catch( ChannelRejectedException ex ) {
      // Expected
    }

    EasyMock.verify( acceptor1, acceptor2, acceptor3 );

    // Scenario 2:
    //  1) Add acceptor 2 (to end)
    //  2) Acceptor 1 will deny connection
    //  2) Acceptor 2 will approve connection
    EasyMock.reset( acceptor1, acceptor2, acceptor3 );

    acceptor1.newChannel( null, null, "B" );
    EasyMock.expectLastCall().andThrow( new ChannelRejectedException() );
    acceptor2.newChannel( null, null, "B" );
    EasyMock.replay( acceptor1, acceptor2, acceptor3 );

    main_acceptor.addDelegate( acceptor2 );

    try {
      main_acceptor.newChannel( null, null, "B" );
    }
    catch( ChannelRejectedException ex ) {
      ex.printStackTrace();
      fail( "Should have worked" );
    }

    EasyMock.verify( acceptor1, acceptor2, acceptor3 );

    // Scenario 2:
    //  1) Add acceptor 3 (to beginning)
    //  2) Acceptor 3 will approve connection
    EasyMock.reset( acceptor1, acceptor2, acceptor3 );

    acceptor3.newChannel( null, null, "C" );
    EasyMock.replay( acceptor1, acceptor2, acceptor3 );

    main_acceptor.addDelegateToFront( acceptor3 );

    try {
View Full Code Here

TOP

Related Classes of com.starlight.intrepid.ChannelAcceptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.