org.htmlparser.tests.lexerTests
Class StreamTests

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.htmlparser.tests.ParserTestCase
              extended byorg.htmlparser.tests.lexerTests.StreamTests
All Implemented Interfaces:
junit.framework.Test

public class StreamTests
extends ParserTestCase


Field Summary
 
Fields inherited from class org.htmlparser.tests.ParserTestCase
mLexer, node, nodeCount, parser
 
Constructor Summary
StreamTests(java.lang.String name)
          Test the first level stream class.
 
Method Summary
 void testClose()
          Test close.
 void testEmpty()
          Test initialization with an empty input stream.
 void testMarkReset()
          Test that mark and reset work as per the contract.
 void testMarkResetThreaded()
          Test that mark and reset work as per the contract when threaded.
 void testNull()
          Test initialization with a null value.
 void testOneByte()
          Test initialization with an input stream having only one byte.
 void testSameBytes()
          Test that the same bytes are returned as with a naked input stream.
 void testThreaded()
          Test that threading works and is faster than a naked input stream.
 
Methods inherited from class org.htmlparser.tests.ParserTestCase
assertHiddenIDTagPresent, assertNodeCount, assertNodeCount, assertSameType, assertStringEquals, assertSuperType, assertTagEquals, assertType, assertXmlEquals, createParser, createParser, createParser, createParser, failWithMessage, getParser, main, parse, parseAndAssertNodeCount, parseNodes, removeEscapeCharacters, setParser
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, name, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assert, assert, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertNotNull, assertNotNull, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StreamTests

public StreamTests(java.lang.String name)
Test the first level stream class.

Method Detail

testNull

public void testNull()
              throws java.io.IOException
Test initialization with a null value.

Throws:
java.io.IOException

testEmpty

public void testEmpty()
               throws java.io.IOException
Test initialization with an empty input stream.

Throws:
java.io.IOException

testOneByte

public void testOneByte()
                 throws java.io.IOException
Test initialization with an input stream having only one byte.

Throws:
java.io.IOException

testSameBytes

public void testSameBytes()
                   throws java.io.IOException
Test that the same bytes are returned as with a naked input stream.

Throws:
java.io.IOException

testThreaded

public void testThreaded()
                  throws java.io.IOException
Test that threading works and is faster than a naked input stream. This, admittedly contrived, test illustrates the following principles:
  • the underlying network code is already multi-threaded, so there may not be a need to use application level threading in most cases
  • results may vary based on network connection speed, JVM, and especially application usage pattterns
  • issues only show up with large files, in my case greater than about 72,400 bytes, since the underlying network code reads that far into the socket before throttling back and waiting
  • this is only applicable to TCP/IP usage, disk access would not have this problem, since the cost of reading disk is much less than the round-trip cost of a TCP/IP handshake
  • So, what does it do? It sets up to read a URL two ways, once with a naked input stream, and then with the Stream class. In each case, before reading, it delays about 2 seconds (for me anyway) to allow the java.net implementation to read ahead and then throttle back. The threaded Stream though keeps reading while this delay is going on and hence gets a big chunk of the file in memory. This advantage translates to a faster spin through the bytes after the delay.

    Throws:
    java.io.IOException

    testMarkReset

    public void testMarkReset()
                       throws java.io.IOException
    Test that mark and reset work as per the contract.

    Throws:
    java.io.IOException

    testMarkResetThreaded

    public void testMarkResetThreaded()
                               throws java.io.IOException
    Test that mark and reset work as per the contract when threaded.

    Throws:
    java.io.IOException

    testClose

    public void testClose()
                   throws java.io.IOException
    Test close.

    Throws:
    java.io.IOException