The version of Apache log4j used by SoundHelix.
Clone
HTTPS:
git clone https://vervis.peers.community/repos/aEp6o
SSH:
git clone USERNAME@vervis.peers.community:aEp6o
Branches
Tags
- 1.3alpha-7
- CHAINSAW_2_SANDBOX_MERGE
- CORE_VERSION
- LEVEL_REPLACES_PRIORITY
- PREALPHA_1_3_AS_OF_2004_05_12
- PRE_CHAINSAW_MODEL_CONVERSION
- PRE_UGLI_MOVE
- TAG_CHAINSAW2_MOVE
- log4j-1.2.17
- log4j-1.2.17-rc1
- v1.3alpha8
- v1.3alpha8-temp
- v1_2_1
- v1_2_10-recalled
- v1_2_11
- v1_2_11_rc1
- v1_2_11rc3
- v1_2_12
- v1_2_12_rc1
- v1_2_12_rc2
- v1_2_12_rc3
- v1_2_12_rc4
- v1_2_12_rc5
- v1_2_12_rc6
- v1_2_13
- v1_2_13_rc1
- v1_2_13_rc2
- v1_2_13_site_update
- v1_2_14
- v1_2_14_maven
- v1_2_14_rc1
- v1_2_14_site_update
- v1_2_15
- v1_2_15_rc1
- v1_2_15_rc2
- v1_2_15_rc3
- v1_2_15_rc4
- v1_2_15_rc5
- v1_2_15_rc6
- v1_2_16
- v1_2_16_rc1
- v1_2_16_rc2
- v1_2_17
- v1_2_17-rc1
- v1_2_17_rc1
- v1_2_17_rc2
- v1_2_17_rc3
- v1_2_2
- v1_2_3
- v1_2_4
- v1_2_6
- v1_2_7
- v1_2_9
- v1_2_alpha0
- v1_2_alpha7
- v1_2beta1
- v1_2final
- v1_3alpha_1
- v1_3alpha_6
- v_1_0
- v_1_0_1
- v_1_0_4
- v_1_1
- v_1_1_1
- v_1_1_2
- v_1_1_3
- v_1_1_b1
- v_1_1b2
- v_1_1b3
- v_1_1b5
- v_1_1b6
- v_1_1b7
- v_1_2beta3
ReaderWriterLockTestCase.java
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed 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.
*/
package org.apache.log4j.helpers;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import java.io.BufferedReader;
import java.io.PipedReader;
import java.io.PipedWriter;
import java.io.PrintWriter;
/**
* This test checks the correctness of ReaderWriterLock.
*
* <b>Warning</b> This test should not use log4j loggers.
*
* There is not much point in having a test depend on the component being tested.
*
* @author Ceki Gülcü
*
*/
public class ReaderWriterLockTestCase extends TestCase {
static final int NUM_READERS = 120; //120;
static final int NUM_WRITERS = 4; //4;
static long WLOOP; // number of repetitions for writer threads
static long RLOOP; // number of repetitions for reader threads
double value1 = 0;
double value2 = 0;
// this is the object we are testing:
ReaderWriterLock lock;
// The bufferedReader will be passed to the VerifierThread
BufferedReader bufferedReader;
// This is wehere readers and writers send their output
PrintWriter printWriter;
/**
* Constructor for ReaderWriterLockTestCase.
* @param arg0
*/
public ReaderWriterLockTestCase(String arg0) {
super(arg0);
}
protected void setUp() throws Exception {
// We write to a piped buffer so that a verifer thread can check the output
PipedWriter pipedWriter = new PipedWriter();
PipedReader pipedReader = new PipedReader();
bufferedReader = new BufferedReader(pipedReader);
pipedReader.connect(pipedWriter);
printWriter = new PrintWriter(pipedWriter);
lock = new ReaderWriterLock(printWriter);
}
protected void tearDown() throws Exception {
}
public void test1() throws Exception {
WLOOP = Long.parseLong(System.getProperty("runLen"));
RLOOP = (long) (WLOOP * (1.0)); // readers loop longer
Thread[] threads = new Thread[NUM_READERS + NUM_WRITERS];
VerifierThread vt =
new VerifierThread(bufferedReader, NUM_READERS, NUM_WRITERS);
vt.start();
for (int i = 0; i < NUM_READERS; i++) {
threads[i] = new ReaderThread(i, vt);
}
for (int i = 0; i < NUM_WRITERS; i++) {
threads[NUM_READERS + i] = new WriterThread(i, vt);
}
for (int i = 0; i < (NUM_WRITERS + NUM_READERS); i++) {
threads[i].start();
}
// It's better to wait for the writer to finish first
for (int i = 0; i < (NUM_WRITERS + NUM_READERS); i++) {
try {
threads[i].join();
} catch (InterruptedException e) {
}
}
// let the verifier thread close
vt.closed = true;
Exception e = vt.getException();
if (e != null) {
throw e;
}
}
void delay(long delay) {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
}
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new ReaderWriterLockTestCase("test1"));
return suite;
}
void printMessage(String msg) {
//printWriter.print("[");
printWriter.println(Thread.currentThread().getName()+" "+msg);
}
class ReaderThread extends Thread {
int tNum;
VerifierThread vt;
ReaderThread(int i, VerifierThread vt) {
super("R-" + i);
tNum = i;
this.vt = vt;
}
public void run() {
printMessage("In run()");
for (int t = 0; t < RLOOP; t++) {
if (vt.isClosed()) {
return;
}
//printMessage("Asking for read lock.");
lock.getReadLock();
//printMessage("Got read lock.");
printMessage("Value1 is " + value1);
printMessage("Value2 is " + value2);
delay(10);
//printMessage("About to release read lock.");
lock.releaseReadLock();
}
}
}
class WriterThread extends Thread {
int tNum;
VerifierThread vt;
WriterThread(int i, VerifierThread vt) {
super("W-" + i);
tNum = i;
this.vt = vt;
}
public void run() {
printMessage("In run");
for (int t = 0; t < WLOOP; t++) {
if (vt.isClosed()) {
return;
}
// on average, the wait is (3.5)*30
delay((((tNum * 13) + t) % 7) * 30);
//printMessage("Asking for write lock.");
lock.getWriteLock();
//printMessage("Got write lock.");
printMessage("About to increment values.");
value1 += 1;
value2 += 10;
delay(10);
//printMessage("About to release write lock.");
lock.releaseWriteLock();
}
}
}
}