package com.tagtraum.perf.gcviewer.imp;

import junit.framework.TestCase;
import junit.framework.TestSuite;

import java.io.StringBufferInputStream;
import java.io.ByteArrayInputStream;
import java.util.Iterator;

import com.tagtraum.perf.gcviewer.GCEvent;
import com.tagtraum.perf.gcviewer.DataReader;
import com.tagtraum.perf.gcviewer.GCModel;

/**
 *
 * Date: Jan 30, 2002
 * Time: 5:53:55 PM
 * @author <a href="mailto:hs@tagtraum.com">Hendrik Schreiber</a>
 * @version $Id: $
 */
public class TestDataReaderSun1_4_0 extends TestCase {

    public TestDataReaderSun1_4_0(String name) {
        super(name);
    }

    public void testParse1() throws Exception {
        GCEvent event1 = new GCEvent(2.23492e-006d, 8968, 8230, 10912, 0.0037192d, GCEvent.Type.GC);
        GCEvent event2 = new GCEvent(1, 8968, 8230, 10912, 0.0037192d, GCEvent.Type.GC);
        GCEvent event3 = new GCEvent(2, 8968, 8230, 10912, 0.0037192d, GCEvent.Type.GC);
        GCEvent event4 = new GCEvent(3, 10753, 6046, 10912, 0.3146707d, GCEvent.Type.FULL_GC);
        GCEvent event5 = new GCEvent(4, 10753, 6046, 10912, 0.3146707d, GCEvent.Type.INC_GC);
        GCEvent event6 = new GCEvent(5, 52471, 22991, 75776, 1.0754938d, GCEvent.Type.GC);
        ByteArrayInputStream in = new ByteArrayInputStream("2.23492e-006: [GC 8968K->8230K(10912K), 0.0037192 secs]\r\n1.0: [GC 8968K->8230K(10912K), 0.0037192 secs]\r\n2.0: [GC 8968K->8230K(10912K), 0.0037192 secs]\r\n3.0: [Full GC 10753K->6046K(10912K), 0.3146707 secs]\r\n4.0: [Inc GC 10753K->6046K(10912K), 0.3146707 secs]\r\n5.0: [GC Desired survivor size 3342336 bytes, new threshold 1 (max 32) - age   1:  6684672 bytes,  6684672 total 52471K->22991K(75776K), 1.0754938 secs]".getBytes());
        DataReader reader = new DataReaderSun1_4_0(in);
        GCModel model = reader.read();
        assertTrue(model.size() == 6);
        Iterator i = model.getGCEvents();
        GCEvent event = (GCEvent) i.next();
        assertEquals(event, event1);
        event = (GCEvent) i.next();
        assertEquals(event, event2);
        event = (GCEvent) i.next();
        assertEquals(event, event3);
        event = (GCEvent) i.next();
        assertEquals(event, event4);
        event = (GCEvent) i.next();
        assertEquals(event, event5);
        event = (GCEvent) i.next();
        assertEquals(event, event6);
    }

    public static TestSuite suite() {
        return new TestSuite(TestDataReaderSun1_4_0.class);
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(suite());
    }
}
