package org.socketio.netty.session;

import io.netty.util.HashedWheelTimer;
import org.jmock.Expectations;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.lib.concurrent.Synchroniser;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.jmock.Mockery;

import java.util.concurrent.TimeUnit;


public class SocketIOHeartbeatSchedulerTest {

    private HashedWheelTimer timer;
    private SocketIOHeartbeatScheduler scheduler;

    private Mockery jmockContext;
    private IManagedSession session;

    @Before
    public void init(){
        timer = new HashedWheelTimer();
        timer.start();
        jmockContext = new JUnit4Mockery() {{
            setThreadingPolicy(new Synchroniser());
        }};
        SocketIOHeartbeatScheduler.setHashedWheelTimer(timer);
        SocketIOHeartbeatScheduler.setHeartbeatInterval(1);
        SocketIOHeartbeatScheduler.setHeartbeatTimeout(3);
        session = jmockContext.mock(IManagedSession.class);
        scheduler = new SocketIOHeartbeatScheduler(session);
    }

    @After
    public void destroy(){
        timer.stop();
    }

    @Test
    public void testReschedule() throws Exception {

        jmockContext.checking(new Expectations() {
            {
                exactly(2).of(session).sendHeartbeat();
                oneOf(session).disconnect();
                oneOf(session).getSessionId();
            }

        });
        scheduler.reschedule();
        TimeUnit.SECONDS.sleep(4);
        jmockContext.assertIsSatisfied();
    }

    @Test
    public void testRescheduleNotDisconnect() throws Exception {

        jmockContext.checking(new Expectations() {
            {
                exactly(1).of(session).sendHeartbeat();
            }

        });
        scheduler.reschedule();
        TimeUnit.MILLISECONDS.sleep(1500);
        jmockContext.assertIsSatisfied();
    }
}
@@ -1,8 +1,620 @@
+/**%0A * Copyright 2012 Ronen Hamias, Anton Kharenko%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A
 package 

Add header