Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #725 #727

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public boolean isNeverBlock() {
/**
* The remaining capacity available in the blocking queue.
* <p>
* See also {@link java.util.concurrent.BlockingQueue#remainingCapacity()
* See also {@link BlockingQueue#remainingCapacity()
* BlockingQueue#remainingCapacity()}
*
* @return the remaining capacity
Expand Down Expand Up @@ -275,14 +275,23 @@ public boolean isAttached(Appender<E> eAppender) {

public void detachAndStopAllAppenders() {
aai.detachAndStopAllAppenders();
appenderCount = 0;
}

public boolean detachAppender(Appender<E> eAppender) {
return aai.detachAppender(eAppender);
boolean detached = aai.detachAppender(eAppender);
if (detached) {
appenderCount --;
}
return detached;
}

public boolean detachAppender(String name) {
return aai.detachAppender(name);
boolean detached = aai.detachAppender(name);
if (detached) {
appenderCount --;
}
return detached;
}

class Worker extends Thread {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,56 @@ public void checkThatStartMethodIsIdempotent() {
// thread
asyncAppenderBase.start();
}

// AsyncAppenderBase can not addAppender after detachAppender
@Test
@Timeout(value=2, unit = TimeUnit.SECONDS)
public void appenderShouldBeAddedSuccessfullyAfterDetachedByReference() {
asyncAppenderBase.addAppender(listAppender);
asyncAppenderBase.start();
asyncAppenderBase.doAppend(0);
asyncAppenderBase.detachAppender(listAppender);
asyncAppenderBase.addAppender(listAppender);
asyncAppenderBase.doAppend(0);
asyncAppenderBase.stop();
verify(listAppender, 2);
}

@Test
@Timeout(value=2, unit = TimeUnit.SECONDS)
public void appenderShouldBeAddedSuccessfullyAfterDetachedByName() {
asyncAppenderBase.addAppender(listAppender);
asyncAppenderBase.start();
asyncAppenderBase.doAppend(0);
asyncAppenderBase.detachAppender("list");
asyncAppenderBase.addAppender(listAppender);
asyncAppenderBase.doAppend(0);
asyncAppenderBase.stop();
verify(listAppender, 2);
}

@Test
@Timeout(value=2, unit = TimeUnit.SECONDS)
public void appenderShouldBeAddedSuccessfullyAfterAllAppendersDetachedAndStopeed() throws InterruptedException {
asyncAppenderBase.addAppender(listAppender);
asyncAppenderBase.start();
asyncAppenderBase.doAppend(0);
TimeUnit.SECONDS.sleep(1);
asyncAppenderBase.detachAndStopAllAppenders();

ListAppender<Integer> listAppender2 = new ListAppender<Integer>();
listAppender2.setContext(context);
listAppender2.setName("list2");
listAppender2.start();

asyncAppenderBase.addAppender(listAppender2);
asyncAppenderBase.doAppend(0);

asyncAppenderBase.stop();

verify(listAppender, 1);
verify(listAppender2, 1);

}

}