KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > server > uihandler > LogsManagerTerminateTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.server.uihandler;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.logging.Level JavaDoc;
25 import org.netbeans.junit.Log;
26 import org.netbeans.junit.NbTestCase;
27
28 /**
29  *
30  * @author Jaroslav Tulach
31  */

32 public class LogsManagerTerminateTest extends NbTestCase {
33     private LogsManager result;
34     private File JavaDoc logs;
35     
36     
37     public LogsManagerTerminateTest(String JavaDoc testName) {
38         super(testName);
39     }
40     
41     @Override JavaDoc
42     protected Level JavaDoc logLevel() {
43         return Level.FINE;
44     }
45     
46     private File JavaDoc logs() throws IOException JavaDoc {
47         File JavaDoc f = new File JavaDoc(getWorkDir(), "logs");
48         f.mkdirs();
49         return f;
50     }
51     
52     
53     protected void setUp() throws Exception JavaDoc {
54         clearWorkDir();
55
56         File JavaDoc toDir = logs();
57         for (int i = 400; i < 600; i++) {
58             File JavaDoc log = LogsManagerTest.extractResourceAs(toDir, "3.log", "log" + i);
59         }
60         
61     }
62     
63     protected void tearDown() throws Exception JavaDoc {
64     }
65     
66     public void testWeAreAbleToStopParsingInMiddle() throws Exception JavaDoc {
67         CharSequence JavaDoc log = Log.enable("org.netbeans.server.uihandler", Level.INFO);
68         result = LogsManager.createManager(logs());
69         
70         // stop parsing
71
result.close();
72         
73         // wait if there are logs, then parsing is likely going on
74
int prev = -1;
75         for (int i = 0; i < 100; i++) {
76             int len = log.length();
77             if (prev == len) {
78                 break;
79             }
80             prev = len;
81             Thread.sleep(100);
82         }
83         
84         if (log.toString().indexOf("550") >= 0) {
85             fail("We shall not parse file log550:\n" + log);
86         }
87     }
88     
89 }
90
Popular Tags