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

[INLONG-8334][Agent] Optimize agent UT of agent to avoid failed #8335

Merged
merged 1 commit into from
Jun 27, 2023
Merged
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 @@ -32,6 +32,7 @@
import org.apache.inlong.agent.plugin.sinks.MockSink;
import org.apache.inlong.agent.plugin.sources.TextFileSource;
import org.apache.inlong.agent.plugin.sources.reader.file.MonitorTextFile;
import org.apache.inlong.agent.plugin.trigger.TestTriggerManager;
import org.apache.inlong.agent.plugin.utils.TestUtils;
import org.apache.inlong.common.metric.MetricItem;
import org.apache.inlong.common.metric.MetricRegister;
Expand All @@ -48,6 +49,8 @@
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -76,6 +79,7 @@
@PowerMockIgnore({"javax.management.*"})
public class TestTextFileTask {

private static final Logger LOGGER = LoggerFactory.getLogger(TestTriggerManager.class);
public static final TemporaryFolder TMP_FOLDER = new TemporaryFolder();
private static final Gson GSON = new Gson();
private static TaskManager taskManager;
Expand Down Expand Up @@ -185,7 +189,13 @@ public void testReadFull() throws IOException {
jobProfile.set(JOB_FILE_META_ENV_LIST, ENV_CVM);
// mock data
final MockSink sink = mockTextTask(jobProfile);

LOGGER.info("sink getResult1 size: {}", sink.getResult().size());

await().atMost(10, TimeUnit.SECONDS).until(() -> sink.getResult().size() == 5);

LOGGER.info("sink getResult2 size: {}", sink.getResult().size());

await().atMost(10, TimeUnit.SECONDS).until(() -> MonitorTextFile.getInstance().monitorNum() == 1);
String testData = IntStream.range(5, 10)
.mapToObj(String::valueOf)
Expand All @@ -194,7 +204,12 @@ public void testReadFull() throws IOException {
sb.append(System.lineSeparator());
TestUtils.write(file.getAbsolutePath(), sb);

await().atMost(10, TimeUnit.SECONDS).until(() -> sink.getResult().size() == 5);
LOGGER.info("sink getResult3 size: {}", sink.getResult().size());

await().atMost(10, TimeUnit.SECONDS).until(() -> sink.getResult().size() >= 5);

LOGGER.info("sink getResult4 size: {}", sink.getResult().size());

synchronized (this) {
String collectData = sink.getResult().stream().map(message -> {
String content = new String(message.getBody(), StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public void teardownEach() {

@Test
public void testRestartTriggerJobRestore() throws Exception {
agent.cleanupTriggers();
agent.cleanupJobs();

TriggerProfile triggerProfile1 = TriggerProfile.parseJsonStr(FILE_JOB_TEMPLATE);
triggerProfile1.set(JobConstants.JOB_ID, "1");
Expand All @@ -114,6 +116,9 @@ public void testRestartTriggerJobRestore() throws Exception {

@Test
public void testMultiTriggerWatchSameDir() throws Exception {
agent.cleanupTriggers();
agent.cleanupJobs();

TriggerProfile triggerProfile1 = TriggerProfile.parseJsonStr(FILE_JOB_TEMPLATE);
triggerProfile1.set(JobConstants.JOB_ID, "1");
triggerProfile1.set(JobConstants.JOB_DIR_FILTER_PATTERNS,
Expand All @@ -138,6 +143,9 @@ public void testMultiTriggerWatchSameDir() throws Exception {

@Test
public void testSubmitAndShutdown() throws Exception {
agent.cleanupTriggers();
agent.cleanupJobs();

TriggerProfile triggerProfile1 = TriggerProfile.parseJsonStr(FILE_JOB_TEMPLATE);
triggerProfile1.set(JobConstants.JOB_ID, "1");
triggerProfile1.set(JobConstants.JOB_DIR_FILTER_PATTERNS,
Expand Down