knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject git commit: KNOX-319: Fixed test issue causing build failure on windows. (cherry picked from commit 25c3c695422ded37bf0dfd93e933bccc2b1dc45b)
Date Tue, 01 Apr 2014 21:48:43 GMT
Repository: knox
Updated Branches:
  refs/heads/v0.4.0 c9ce1623d -> cde0cc024


KNOX-319: Fixed test issue causing build failure on windows.
(cherry picked from commit 25c3c695422ded37bf0dfd93e933bccc2b1dc45b)


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/cde0cc02
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/cde0cc02
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/cde0cc02

Branch: refs/heads/v0.4.0
Commit: cde0cc024277cda25f1e7076b41683bf46ef749c
Parents: c9ce162
Author: Kevin Minder <kevin.minder@hortonworks.com>
Authored: Tue Apr 1 17:48:04 2014 -0400
Committer: Kevin Minder <kevin.minder@hortonworks.com>
Committed: Tue Apr 1 17:48:36 2014 -0400

----------------------------------------------------------------------
 .../gateway/audit/log4j/appender/JdbmQueue.java |  7 +++-
 .../appender/JdbmStoreAndForwardAppender.java   | 10 ++++-
 .../hadoop/gateway/audit/AuditLayoutTest.java   | 29 +++++++++----
 .../hadoop/gateway/audit/AuditServiceTest.java  | 40 +++++++++++++-----
 .../hadoop/gateway/audit/JdbmQueueTest.java     | 43 ++++++++++++++------
 .../audit/StoreAndForwardAppenderTest.java      | 34 ++++++++++------
 .../src/test/resources/audit-log4j.properties   | 25 ++++++++++++
 .../src/test/resources/log4j.properties         | 25 ------------
 8 files changed, 144 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/cde0cc02/gateway-util-common/src/main/java/org/apache/hadoop/gateway/audit/log4j/appender/JdbmQueue.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/audit/log4j/appender/JdbmQueue.java
b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/audit/log4j/appender/JdbmQueue.java
index 0a3f766..86659bd 100644
--- a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/audit/log4j/appender/JdbmQueue.java
+++ b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/audit/log4j/appender/JdbmQueue.java
@@ -112,11 +112,16 @@ public class JdbmQueue<E> {
     return committed;
   }
 
-  public synchronized void close() {
+  public synchronized void stop() {
     open = false;
     notifyAll();
   }
 
+  public synchronized void close() throws IOException {
+    stop();
+    db.close();
+  }
+
   long findStat() throws IOException {
     long recid = db.getNamedObject( STAT_NAME );
     if ( recid == 0 ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/cde0cc02/gateway-util-common/src/main/java/org/apache/hadoop/gateway/audit/log4j/appender/JdbmStoreAndForwardAppender.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/audit/log4j/appender/JdbmStoreAndForwardAppender.java
b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/audit/log4j/appender/JdbmStoreAndForwardAppender.java
index 6aa11c8..a2a09ed 100644
--- a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/audit/log4j/appender/JdbmStoreAndForwardAppender.java
+++ b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/audit/log4j/appender/JdbmStoreAndForwardAppender.java
@@ -78,7 +78,15 @@ public class JdbmStoreAndForwardAppender extends AppenderSkeleton {
 
   @Override
   public void close() {
-    queue.close();
+    try {
+      queue.stop();
+      forwarder.join();
+      queue.close();
+    } catch( InterruptedException e ) {
+      throw new RuntimeException( e );
+    } catch( IOException e ) {
+      throw new RuntimeException( e );
+    }
   }
 
   private class Forwarder extends Thread {

http://git-wip-us.apache.org/repos/asf/knox/blob/cde0cc02/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/AuditLayoutTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/AuditLayoutTest.java
b/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/AuditLayoutTest.java
index 8a74289..a58ef59 100644
--- a/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/AuditLayoutTest.java
+++ b/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/AuditLayoutTest.java
@@ -17,12 +17,6 @@
  */
 package org.apache.hadoop.gateway.audit;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
 import org.apache.hadoop.gateway.audit.api.AuditContext;
 import org.apache.hadoop.gateway.audit.api.AuditService;
 import org.apache.hadoop.gateway.audit.api.AuditServiceFactory;
@@ -33,11 +27,20 @@ import org.apache.hadoop.gateway.audit.api.CorrelationServiceFactory;
 import org.apache.hadoop.gateway.audit.log4j.audit.AuditConstants;
 import org.apache.hadoop.gateway.audit.log4j.layout.AuditLayout;
 import org.apache.hadoop.test.log.CollectAppender;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.PropertyConfigurator;
 import org.apache.log4j.spi.LoggingEvent;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
 public class AuditLayoutTest {
   private static AuditService auditService = AuditServiceFactory.getAuditService();
   private static CorrelationService correlationService = CorrelationServiceFactory.getCorrelationService();
@@ -67,13 +70,25 @@ public class AuditLayoutTest {
 
   @Before
   public void setup() {
-    CollectAppender.queue.clear();
+    cleanup();
   }
 
   @After
   public void cleanup() {
+    CollectAppender.queue.clear();
     auditService.detachContext();
     correlationService.detachContext();
+    LogManager.shutdown();
+    String absolutePath = "target/audit";
+    File db = new File( absolutePath + ".db" );
+    if( db.exists() ) {
+      assertThat( "Failed to delete audit store db file.", db.delete(), is( true ) );
+    }
+    File lg = new File( absolutePath + ".lg" );
+    if( lg.exists() ) {
+      assertThat( "Failed to delete audit store lg file.", lg.delete(), is( true ) );
+    }
+    PropertyConfigurator.configure( ClassLoader.getSystemResourceAsStream( "audit-log4j.properties"
) );
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/knox/blob/cde0cc02/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/AuditServiceTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/AuditServiceTest.java
b/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/AuditServiceTest.java
index ff9fecf..31d1c68 100644
--- a/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/AuditServiceTest.java
+++ b/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/AuditServiceTest.java
@@ -17,13 +17,6 @@
  */
 package org.apache.hadoop.gateway.audit;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.IsNull.nullValue;
-
-import java.util.Iterator;
-import java.util.UUID;
-
 import org.apache.hadoop.gateway.audit.api.AuditContext;
 import org.apache.hadoop.gateway.audit.api.AuditService;
 import org.apache.hadoop.gateway.audit.api.AuditServiceFactory;
@@ -35,10 +28,21 @@ import org.apache.hadoop.gateway.audit.log4j.audit.AuditConstants;
 import org.apache.hadoop.gateway.audit.log4j.audit.Log4jAuditService;
 import org.apache.hadoop.gateway.audit.log4j.correlation.Log4jCorrelationService;
 import org.apache.hadoop.test.log.CollectAppender;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.PropertyConfigurator;
 import org.apache.log4j.spi.LoggingEvent;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import java.io.File;
+import java.util.Iterator;
+import java.util.UUID;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsNull.nullValue;
+
 public class AuditServiceTest {
   private static AuditService auditService = AuditServiceFactory.getAuditService();
   private static CorrelationService correlationService = CorrelationServiceFactory.getCorrelationService();
@@ -49,12 +53,28 @@ public class AuditServiceTest {
   private String remoteIp = "127.0.0.1";
   private String remoteHostname = "localhost";
   private String targetServiceName = "service";
-  
+
   @Before
-  public void cleanAppenderDb() {
+  public void setup() {
+    cleanup();
+  }
+
+  @After
+  public void cleanup() {
     CollectAppender.queue.clear();
+    LogManager.shutdown();
+    String absolutePath = "target/audit";
+    File db = new File( absolutePath + ".db" );
+    if( db.exists() ) {
+      assertThat( "Failed to delete audit store db file.", db.delete(), is( true ) );
+    }
+    File lg = new File( absolutePath + ".lg" );
+    if( lg.exists() ) {
+      assertThat( "Failed to delete audit store lg file.", lg.delete(), is( true ) );
+    }
+    PropertyConfigurator.configure( ClassLoader.getSystemResourceAsStream( "audit-log4j.properties"
) );
   }
-  
+
   @Test
   public void testMultipleRequestEvents() {
     int iterations = 1000;

http://git-wip-us.apache.org/repos/asf/knox/blob/cde0cc02/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/JdbmQueueTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/JdbmQueueTest.java
b/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/JdbmQueueTest.java
index b1d5d19..abe4648 100644
--- a/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/JdbmQueueTest.java
+++ b/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/JdbmQueueTest.java
@@ -19,6 +19,8 @@ package org.apache.hadoop.gateway.audit;
 
 import org.apache.hadoop.gateway.audit.log4j.appender.JdbmQueue;
 import org.apache.log4j.LogManager;
+import org.apache.log4j.PropertyConfigurator;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -34,6 +36,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
 
 public class JdbmQueueTest {
 
@@ -42,25 +45,33 @@ public class JdbmQueueTest {
 
   @Before
   public void setup() throws IOException {
-    LogManager.getCurrentLoggers();
     file = new File( "target/JdbmQueueTest" );
     cleanup();
     queue = new JdbmQueue<String>( file );
   }
 
-  public void cleanup() {
-    File db = new File( file.getAbsolutePath() + ".db" );
+  @After
+  public void cleanup() throws IOException {
+    if( queue != null ) {
+      queue.close();
+      queue = null;
+    }
+    LogManager.shutdown();
+    String absolutePath = "target/audit";
+    File db = new File( absolutePath + ".db" );
     if( db.exists() ) {
-      assertThat( db.delete(), is( true ) );
+      assertThat( "Failed to delete audit store db file.", db.delete(), is( true ) );
     }
-    File lg = new File( file.getAbsolutePath() + ".lg" );
+    File lg = new File( absolutePath + ".lg" );
     if( lg.exists() ) {
-      assertThat( lg.delete(), is( true ) );
+      assertThat( "Failed to delete audit store lg file.", lg.delete(), is( true ) );
     }
+    PropertyConfigurator.configure( ClassLoader.getSystemResourceAsStream( "audit-log4j.properties"
) );
   }
 
   @Test
   public void testSimple() throws IOException, InterruptedException {
+    System.out.println( "Running " + Thread.currentThread().getStackTrace()[1].getClassName()
+ "#" + Thread.currentThread().getStackTrace()[1].getMethodName() );
     String one = UUID.randomUUID().toString();
     String two = UUID.randomUUID().toString();
     String three = UUID.randomUUID().toString();
@@ -87,6 +98,7 @@ public class JdbmQueueTest {
   @Ignore
   @Test
   public void testPerformanceAndStorageFootprint() throws IOException, InterruptedException
{
+    System.out.println( "Running " + Thread.currentThread().getStackTrace()[1].getClassName()
+ "#" + Thread.currentThread().getStackTrace()[1].getMethodName() );
 
     String fill = createFillString( 100 );
     File dbFile = new File( file.getAbsolutePath() + ".db" );
@@ -120,6 +132,7 @@ public class JdbmQueueTest {
   @Ignore
   @Test
   public void testFileGrowth() throws IOException, InterruptedException {
+    System.out.println( "Running " + Thread.currentThread().getStackTrace()[1].getClassName()
+ "#" + Thread.currentThread().getStackTrace()[1].getMethodName() );
 
     String fill = createFillString( 100 );
     File dbFile = new File( file.getAbsolutePath() + ".db" );
@@ -152,7 +165,9 @@ public class JdbmQueueTest {
   }
 
   @Test( timeout = 120000 )
-  public void testConcurrentConsumer() throws InterruptedException {
+  public void testConcurrentConsumer() throws InterruptedException, IOException {
+    System.out.println( "Running " + Thread.currentThread().getStackTrace()[1].getClassName()
+ "#" + Thread.currentThread().getStackTrace()[1].getMethodName() );
+
     int iterations = 100;
     HashSet<String> consumed = new HashSet<String>();
     Consumer consumer = new Consumer( consumed );
@@ -166,13 +181,15 @@ public class JdbmQueueTest {
     while (consumed.size() < iterations * 2) {
       Thread.sleep( 5 );
     }
-    queue.close();
+    queue.stop();
     consumer.join();
-    assertThat( consumed.size(), is( iterations * 2 ) );
+    assertThat( consumed, hasSize( iterations * 2 ) );
   }
 
   @Test( timeout=120000 )
-  public void testConcurrentProcessor() throws InterruptedException {
+  public void testConcurrentProcessor() throws InterruptedException, IOException {
+    System.out.println( "Running " + Thread.currentThread().getStackTrace()[1].getClassName()
+ "#" + Thread.currentThread().getStackTrace()[1].getMethodName() );
+
     int iterations = 100;
     HashSet<String> consumed = new HashSet<String>();
     Processor consumer = new Processor( consumed );
@@ -186,9 +203,9 @@ public class JdbmQueueTest {
     while (consumed.size() < iterations * 2) {
       Thread.sleep( 5 );
     }
-    queue.close();
-    //consumer.join();
-    assertThat( consumed.size(), is( iterations * 2 ) );
+    queue.stop();
+    consumer.join();
+    assertThat( consumed, hasSize( iterations * 2 ) );
   }
 
   public class Producer extends Thread {

http://git-wip-us.apache.org/repos/asf/knox/blob/cde0cc02/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/StoreAndForwardAppenderTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/StoreAndForwardAppenderTest.java
b/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/StoreAndForwardAppenderTest.java
index 524cb1d..c6a33a0 100644
--- a/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/StoreAndForwardAppenderTest.java
+++ b/gateway-util-common/src/test/java/org/apache/hadoop/gateway/audit/StoreAndForwardAppenderTest.java
@@ -17,45 +17,55 @@
  */
 package org.apache.hadoop.gateway.audit;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-import java.io.File;
-import java.io.IOException;
-
 import org.apache.hadoop.test.log.CollectAppender;
-import org.apache.log4j.Appender;
+import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import java.io.File;
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
 public class StoreAndForwardAppenderTest {
 
   @Before
   public void setup() throws IOException {
+    cleanup();
+  }
+
+  @After
+  public void cleanup() throws IOException {
+    LogManager.shutdown();
     String absolutePath = "target/audit";
     File db = new File( absolutePath + ".db" );
     if( db.exists() ) {
-      assertThat( db.delete(), is( true ) );
+      assertThat( "Failed to delete audit store db file.", db.delete(), is( true ) );
     }
     File lg = new File( absolutePath + ".lg" );
     if( lg.exists() ) {
-      assertThat( lg.delete(), is( true ) );
+      assertThat( "Failed to delete audit store lg file.", lg.delete(), is( true ) );
     }
+    PropertyConfigurator.configure( ClassLoader.getSystemResourceAsStream( "audit-log4j.properties"
) );
   }
-  
+
   @Test(timeout = 500000)
   public void testAppender() throws Exception {
+    System.out.println( "Running " + Thread.currentThread().getStackTrace()[1].getClassName()
+ "#" + Thread.currentThread().getStackTrace()[1].getMethodName() );
+
     int iterations = 1000;
     Logger logger = Logger.getLogger( "audit.store" );
     for( int i = 1; i <= iterations; i++ ) {
       logger.info( Integer.toString( i ) );
     }
     while( CollectAppender.queue.size() < iterations ) {
+      Thread.sleep( 20 );
     }
     assertThat( CollectAppender.queue.size(), is( iterations ) );
-    Appender appender = (Appender)logger.getAllAppenders().nextElement();
-    appender.close();
   }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/cde0cc02/gateway-util-common/src/test/resources/audit-log4j.properties
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/test/resources/audit-log4j.properties b/gateway-util-common/src/test/resources/audit-log4j.properties
new file mode 100644
index 0000000..050f695
--- /dev/null
+++ b/gateway-util-common/src/test/resources/audit-log4j.properties
@@ -0,0 +1,25 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+log4j.rootLogger=ERROR
+
+log4j.logger.audit.store = INFO, audit-store
+log4j.logger.audit.forward = INFO, audit-forward
+
+log4j.appender.audit-store = org.apache.hadoop.gateway.audit.log4j.appender.JdbmStoreAndForwardAppender
+log4j.appender.audit-store.file = target/audit
+
+log4j.appender.audit-forward = org.apache.hadoop.test.log.CollectAppender
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/cde0cc02/gateway-util-common/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/test/resources/log4j.properties b/gateway-util-common/src/test/resources/log4j.properties
deleted file mode 100644
index 050f695..0000000
--- a/gateway-util-common/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,25 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-log4j.rootLogger=ERROR
-
-log4j.logger.audit.store = INFO, audit-store
-log4j.logger.audit.forward = INFO, audit-forward
-
-log4j.appender.audit-store = org.apache.hadoop.gateway.audit.log4j.appender.JdbmStoreAndForwardAppender
-log4j.appender.audit-store.file = target/audit
-
-log4j.appender.audit-forward = org.apache.hadoop.test.log.CollectAppender
\ No newline at end of file


Mime
View raw message