Skip to content

Commit

Permalink
attempting to fix AsyncAppenderBaseTest and DBAppenderHSQLTest in JDK…
Browse files Browse the repository at this point in the history
… 1.7
  • Loading branch information
ceki committed Apr 17, 2013
1 parent 0afa15d commit b956210
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 50 deletions.
Expand Up @@ -45,20 +45,20 @@ public class DBAppenderHSQLTest {
DBAppender appender;
DriverManagerConnectionSource connectionSource;

int existingRowCount;
int existingEventTableRowCount;
Statement stmt;

@BeforeClass
static public void fixtureSetUp() throws SQLException {
DB_APPENDER_HSQL_TEST_FIXTURE = new DBAppenderHSQLTestFixture();
DB_APPENDER_HSQL_TEST_FIXTURE.setUp();
}
}

@AfterClass
static public void fixtureTearDown() throws SQLException {
static public void fixtureTearDown() throws SQLException {
DB_APPENDER_HSQL_TEST_FIXTURE.tearDown();
}

@Before
public void setUp() throws SQLException {
context = new AccessContext();
Expand All @@ -76,7 +76,7 @@ public void setUp() throws SQLException {
appender.setConnectionSource(connectionSource);

stmt = connectionSource.getConnection().createStatement();
existingRowCount = existingRowCount(stmt);
existingEventTableRowCount = existingEventTableRowCount(stmt);
}

@After
Expand All @@ -87,7 +87,7 @@ public void tearDown() throws SQLException {
stmt.close();
}

int existingRowCount(Statement stmt) throws SQLException {
int existingEventTableRowCount(Statement stmt) throws SQLException {
ResultSet rs = stmt.executeQuery("SELECT count(*) FROM access_event");
int result = -1;
if (rs.next()) {
Expand All @@ -109,10 +109,10 @@ public void testAppendAccessEvent() throws SQLException {

IAccessEvent event = createAccessEvent();
appender.append(event);

Statement stmt = connectionSource.getConnection().createStatement();
ResultSet rs = null;
rs = stmt.executeQuery("SELECT * FROM access_event where EVENT_ID = "+ existingRowCount);
rs = stmt.executeQuery("SELECT * FROM access_event where EVENT_ID = " + existingEventTableRowCount);
if (rs.next()) {
assertEquals(event.getTimeStamp(), rs.getLong(1));
assertEquals(event.getRequestURI(), rs.getString(2));
Expand All @@ -130,33 +130,33 @@ public void testAppendAccessEvent() throws SQLException {
rs.close();
stmt.close();
}


@Test
public void testCheckNoHeadersAreInserted() throws Exception {
setInsertHeadersAndStart(false);

IAccessEvent event = createAccessEvent();
appender.append(event);
StatusPrinter.print(context.getStatusManager());

//Check that no headers were inserted
Statement stmt = connectionSource.getConnection().createStatement();
ResultSet rs = null;
rs = stmt.executeQuery("SELECT * FROM access_event_header");
rs = stmt.executeQuery("SELECT * FROM access_event_header where EVENT_ID = " + existingEventTableRowCount);

assertFalse(rs.next());
rs.close();
stmt.close();
}

@Test
public void testAppendHeaders() throws SQLException {
public void testAppendHeaders() throws SQLException {
setInsertHeadersAndStart(true);

IAccessEvent event = createAccessEvent();
appender.append(event);

Statement stmt = connectionSource.getConnection().createStatement();
ResultSet rs = null;
rs = stmt.executeQuery("SELECT * FROM access_event_header");
Expand Down Expand Up @@ -195,10 +195,10 @@ public void testAppendMultipleEvents() throws SQLException {
}

StatusPrinter.print(context);

Statement stmt = connectionSource.getConnection().createStatement();
ResultSet rs = null;
rs = stmt.executeQuery("SELECT * FROM access_event where requestURI='"+uri+"'");
rs = stmt.executeQuery("SELECT * FROM access_event where requestURI='" + uri + "'");
int count = 0;
while (rs.next()) {
count++;
Expand All @@ -210,9 +210,9 @@ public void testAppendMultipleEvents() throws SQLException {
}

private IAccessEvent createAccessEvent() {
return createAccessEvent("");
return createAccessEvent("");
}

private IAccessEvent createAccessEvent(String uri) {
DummyRequest request = new DummyRequest();
request.setRequestUri(uri);
Expand Down
Expand Up @@ -13,14 +13,11 @@
*/
package ch.qos.logback.access.db;

import junit.framework.*;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

public class PackageTest extends TestCase {
@RunWith(Suite.class)
@Suite.SuiteClasses({DBAppenderHSQLTest.class, DBAppenderIntegrationTest.class})
public class PackageTest {

public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new JUnit4TestAdapter(DBAppenderHSQLTest.class));
suite.addTest(new JUnit4TestAdapter(DBAppenderIntegrationTest.class));
return suite;
}
}
Expand Up @@ -289,7 +289,7 @@ public void testMultipleTo() throws Exception {
logger.addAppender(smtpAppender);
logger.debug("hello");
logger.error("en error", new Exception("an exception"));

Thread.yield();
int expectedEmailCount = oldCount+3;
waitForServerToReceiveEmails(expectedEmailCount);
MimeMessage[] mma = greenMailServer.getReceivedMessages();
Expand All @@ -312,7 +312,7 @@ public void bufferShouldBeResetBetweenMessages() throws Exception {
logger.debug(msg1);
logger.error("error one");

waitUntilEmailIsSent();
Thread.yield();
int expectedEmailCount = oldCount+2;
waitForServerToReceiveEmails(expectedEmailCount);

Expand Down
2 changes: 0 additions & 2 deletions logback-core/pom.xml
Expand Up @@ -108,8 +108,6 @@
<excludes>
<exclude>**/All*Test.java</exclude>
<exclude>**/PackageTest.java</exclude>
<exclude>**/ConsoleAppenderTest.java</exclude>
<exclude>**/TimeBasedRollingTest.java</exclude>
</excludes>
</configuration>
</plugin>
Expand Down
Expand Up @@ -13,16 +13,6 @@
*/
package ch.qos.logback.core.appender;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import ch.qos.logback.core.Appender;
import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.CoreConstants;
Expand All @@ -32,6 +22,15 @@
import ch.qos.logback.core.layout.DummyLayout;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.StatusChecker;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

public class ConsoleAppenderTest extends AbstractAppenderTest<Object> {

Expand Down Expand Up @@ -139,16 +138,18 @@ public void testUTF16BE() throws UnsupportedEncodingException {
public void wrongTarget() {
ConsoleAppender<Object> ca = (ConsoleAppender<Object>) getAppender();
EchoEncoder<Object> encoder = new EchoEncoder<Object>();
System.out.println("xxx");
encoder.setContext(context);
ca.setContext(context);
ca.setTarget("foo");
ca.setEncoder(encoder);
ca.start();
ca.doAppend("a");
StatusChecker checker = new StatusChecker(context);
//21:28:01,246 + WARN in ch.qos.logback.core.ConsoleAppender[null] - [foo] should be one of [SystemOut, SystemErr]
//21:28:01,246 |-WARN in ch.qos.logback.core.ConsoleAppender[null] - Using previously set target, System.out by default.
// StatusPrinter.print(context);

checker.assertContainsMatch(Status.ERROR, "\\[foo\\] should be one of \\[SystemOut, SystemErr\\]");
checker.assertContainsMatch(Status.WARN, "\\[foo\\] should be one of \\[SystemOut, SystemErr\\]");

}

Expand Down
Expand Up @@ -17,10 +17,10 @@
import org.junit.runners.Suite;



@RunWith(Suite.class)
@Suite.SuiteClasses( { DummyAppenderTest.class, ConsoleAppenderTest.class,
FileAppenderTest.class})

@Suite.SuiteClasses({DummyAppenderTest.class,
ConsoleAppenderTest.class,
FileAppenderTest.class})

public class PackageTest {
}
Expand Up @@ -24,7 +24,9 @@ public class DelayingListAppender<E> extends ListAppender<E> {
@Override
public void append(E e) {
try {
Thread.yield();
Thread.sleep(delay);
Thread.yield();
} catch (InterruptedException ie) {
interrupted = true;
}
Expand Down

0 comments on commit b956210

Please sign in to comment.