001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.core.spi;
015
016import org.junit.Before;
017import org.junit.Test;
018
019import static org.junit.Assert.assertEquals;
020
021/**
022 * A
023 *
024 * @author Ceki Gülcü
025 */
026public class ScenarioBasedCyclicBufferTrackerTest {
027
028    CyclicBufferTrackerSimulator simulator;
029    CyclicBufferTrackerSimulator.Parameters parameters = new CyclicBufferTrackerSimulator.Parameters();
030
031    void verify() {
032        CyclicBufferTracker<Object> at = simulator.realCBTracker;
033        CyclicBufferTrackerT<Object> t_at = simulator.t_CBTracker;
034        assertEquals(t_at.liveKeysAsOrderedList(), at.liveKeysAsOrderedList());
035        assertEquals(t_at.lingererKeysAsOrderedList(), at.lingererKeysAsOrderedList());
036    }
037
038    @Before
039    public void setUp() {
040        parameters.keySpaceLen = 128;
041        parameters.maxTimestampInc = ComponentTracker.DEFAULT_TIMEOUT / 2;
042    }
043
044    @Test
045    public void shortTest() {
046        parameters.keySpaceLen = 64;
047        parameters.maxTimestampInc = 500;
048        parameters.simulationLength = 70;
049
050        simulator = new CyclicBufferTrackerSimulator(parameters);
051        simulator.buildScenario();
052        simulator.simulate();
053        verify();
054    }
055
056    @Test
057    public void mediumTest() {
058        parameters.simulationLength = 20000;
059
060        simulator = new CyclicBufferTrackerSimulator(parameters);
061        simulator.buildScenario();
062        simulator.simulate();
063        verify();
064    }
065
066    @Test
067    public void longTest() {
068        parameters.simulationLength = 100 * 1000;
069        simulator = new CyclicBufferTrackerSimulator(parameters);
070        simulator.buildScenario();
071        simulator.simulate();
072        verify();
073    }
074}