-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1972] fix(server): Fix clear leak shuffle data accidentally remove …
…data of new coming appId issue (#1971) ### What changes were proposed in this pull request? Fix clear leak shuffle data accidentally remove data of new coming appId issue ### Why are the changes needed? Fix: #1972 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? No need.
- Loading branch information
1 parent
e62fe7c
commit 0f9d9bc
Showing
8 changed files
with
239 additions
and
7 deletions.
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
common/src/test/java/org/apache/uniffle/common/log/TestLoggerExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.uniffle.common.log; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
import javax.annotation.concurrent.GuardedBy; | ||
|
||
import org.apache.log4j.Level; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.apache.logging.log4j.core.Logger; | ||
import org.apache.logging.log4j.core.appender.AbstractAppender; | ||
import org.junit.jupiter.api.extension.AfterEachCallback; | ||
import org.junit.jupiter.api.extension.BeforeEachCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
||
public class TestLoggerExtension implements BeforeEachCallback, AfterEachCallback { | ||
private static final ExtensionContext.Namespace NAMESPACE = | ||
ExtensionContext.Namespace.create(TestLoggerExtension.class); | ||
private static final String LOG_COLLECTOR_KEY = "TestLogAppender"; | ||
private TestAppender appender; | ||
|
||
@Override | ||
public void beforeEach(ExtensionContext context) { | ||
appender = new TestAppender(); | ||
if (LogManager.getLogger(LogManager.ROOT_LOGGER_NAME) instanceof Logger) { | ||
org.apache.logging.log4j.core.Logger log4jlogger = | ||
(org.apache.logging.log4j.core.Logger) | ||
org.apache.logging.log4j.LogManager.getLogger(LogManager.ROOT_LOGGER_NAME); | ||
appender.start(); | ||
log4jlogger.addAppender(appender); | ||
} | ||
context.getStore(NAMESPACE).put(LOG_COLLECTOR_KEY, this); | ||
} | ||
|
||
@Override | ||
public void afterEach(ExtensionContext context) { | ||
if (LogManager.getLogger(LogManager.ROOT_LOGGER_NAME) instanceof Logger) { | ||
Logger log4jlogger = (Logger) LogManager.getLogger(LogManager.ROOT_LOGGER_NAME); | ||
appender.stop(); | ||
log4jlogger.removeAppender(appender); | ||
} | ||
} | ||
|
||
public static TestLoggerExtension getTestLogger(ExtensionContext context) { | ||
return context.getStore(NAMESPACE).get(LOG_COLLECTOR_KEY, TestLoggerExtension.class); | ||
} | ||
|
||
/** | ||
* Determine if a specific pattern appears in log output. | ||
* | ||
* @param pattern a pattern text to search for in log events | ||
* @return true if a log message containing the pattern exists, false otherwise | ||
*/ | ||
public boolean wasLogged(String pattern) { | ||
return appender.wasLogged(Pattern.compile(".*" + pattern + ".*")); | ||
} | ||
|
||
/** | ||
* Determine if a specific pattern appears in log output with the specified level. | ||
* | ||
* @param pattern a pattern text to search for in log events | ||
* @return true if a log message containing the pattern exists, false otherwise | ||
*/ | ||
public boolean wasLoggedWithLevel(String pattern, Level level) { | ||
return appender.wasLoggedWithLevel(Pattern.compile(".*" + pattern + ".*"), level); | ||
} | ||
|
||
/** | ||
* Count the number of times a specific pattern appears in log messages. | ||
* | ||
* @param pattern Pattern to search for in log events | ||
* @return The number of log messages which match the pattern | ||
*/ | ||
public int logCount(String pattern) { | ||
// [\s\S] will match all character include line break | ||
return appender.logCount(Pattern.compile("[\\s\\S]*" + pattern + "[\\s\\S]*")); | ||
} | ||
|
||
public class TestAppender extends AbstractAppender { | ||
@GuardedBy("this") private final List<LogEvent> events = new ArrayList<>(); | ||
|
||
protected TestAppender() { | ||
super("", null, null, false, null); | ||
} | ||
|
||
/** Determines whether a message with the given pattern was logged. */ | ||
public synchronized boolean wasLogged(Pattern pattern) { | ||
for (LogEvent e : events) { | ||
if (pattern.matcher(e.getMessage().getFormattedMessage()).matches()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** Determines whether a message with the given pattern was logged. */ | ||
public synchronized boolean wasLoggedWithLevel(Pattern pattern, Level level) { | ||
for (LogEvent e : events) { | ||
if (e.getLevel().equals(level) | ||
&& pattern.matcher(e.getMessage().getFormattedMessage()).matches()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** Counts the number of log message with a given pattern. */ | ||
public synchronized int logCount(Pattern pattern) { | ||
int logCount = 0; | ||
for (LogEvent e : events) { | ||
if (pattern.matcher(e.getMessage().getFormattedMessage()).matches()) { | ||
logCount++; | ||
} | ||
} | ||
return logCount; | ||
} | ||
|
||
@Override | ||
public void append(LogEvent event) { | ||
events.add(event); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
common/src/test/java/org/apache/uniffle/common/log/TestLoggerParamResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.uniffle.common.log; | ||
|
||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.api.extension.ParameterContext; | ||
import org.junit.jupiter.api.extension.ParameterResolutionException; | ||
import org.junit.jupiter.api.extension.ParameterResolver; | ||
|
||
public class TestLoggerParamResolver implements ParameterResolver { | ||
@Override | ||
public boolean supportsParameter( | ||
final ParameterContext parameterContext, final ExtensionContext extensionContext) | ||
throws ParameterResolutionException { | ||
return ExtensionContext.class.isAssignableFrom(parameterContext.getParameter().getType()) | ||
&& parameterContext.getIndex() == 0; | ||
} | ||
|
||
@Override | ||
public Object resolveParameter( | ||
final ParameterContext parameterContext, final ExtensionContext extensionContext) | ||
throws ParameterResolutionException { | ||
return extensionContext; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters