Skip to content

Commit 6e736cf

Browse files
committed
Removing diagnostic code
1 parent e23e0ba commit 6e736cf

File tree

5 files changed

+38
-158
lines changed

5 files changed

+38
-158
lines changed

src/main/java/com/cloudbees/jenkins/support/SafeLog.java

-73
This file was deleted.

src/main/java/com/cloudbees/jenkins/support/SupportLogHandler.java

-3
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,10 @@ public void flush() {
177177

178178
@Override
179179
public void close() throws SecurityException {
180-
SafeLog.print("close " + this.logDirectry + " " + this.logFilePrefix);
181180
outputLock.lock();
182181
try {
183182
if (writer != null) {
184183
StreamUtils.closeQuietly(writer);
185-
SafeLog.print("closed " + writer);
186184
writer = null;
187185
}
188186
} finally {
@@ -246,7 +244,6 @@ private void setFile(File file) throws FileNotFoundException {
246244
bos = new BufferedOutputStream(fos);
247245
writer = new OutputStreamWriter(bos, StandardCharsets.UTF_8);
248246
setWriter(writer);
249-
SafeLog.print("setWriter " + file);
250247
fileCount = 0;
251248
success = true;
252249
} finally {

src/main/java/com/cloudbees/jenkins/support/SupportPlugin.java

-10
Original file line numberDiff line numberDiff line change
@@ -859,31 +859,26 @@ public LogInitializer(FilePath rootPath, Level level) {
859859
}
860860

861861
public Void call() {
862-
SafeLog.print("LogInitializer on " + rootPath);
863862
// avoid double installation of the handler. JNLP agents can reconnect to the controller multiple times
864863
// and each connection gets a different RemoteClassLoader, so we need to evict them by class name,
865864
// not by their identity.
866865
closeAll();
867866
Runtime.getRuntime().addShutdownHook(new Thread(LogInitializer::closeAll, "close log handlers"));
868-
SafeLog.print("initialized hook");
869867
LogHolder.AGENT_LOG_HANDLER.setLevel(level);
870868
LogHolder.AGENT_LOG_HANDLER.setDirectory(new File(rootPath.getRemote(), SUPPORT_DIRECTORY_NAME), "all");
871869
ROOT_LOGGER.addHandler(LogHolder.AGENT_LOG_HANDLER);
872870
return null;
873871
}
874872

875873
private static void closeAll() {
876-
SafeLog.print("closeAll");
877874
for (Handler h : ROOT_LOGGER.getHandlers()) {
878875
if (h.getClass()
879876
.getName()
880877
.equals(LogHolder.AGENT_LOG_HANDLER.getClass().getName())) {
881878
ROOT_LOGGER.removeHandler(h);
882879
try {
883880
h.close();
884-
SafeLog.print("removed " + h);
885881
} catch (Throwable t) {
886-
SafeLog.print("close failure: " + t);
887882
}
888883
}
889884
}
@@ -927,12 +922,7 @@ public void onOnline(Computer c, TaskListener listener) throws IOException, Inte
927922
if (channel != null) {
928923
final FilePath rootPath = node.getRootPath();
929924
if (rootPath != null) {
930-
SafeLog.print("will call on " + rootPath);
931925
CallAsyncWrapper.callAsync(channel, new LogInitializer(rootPath, getLogLevel()));
932-
// Note that this may or may not run before the test completes; to force it to run:
933-
// Thread.sleep(3000);
934-
// alternately:
935-
// channel.call(new LogInitializer(rootPath, getLogLevel()));
936926
}
937927
}
938928
} catch (IOException e) {

src/test/java/com/cloudbees/jenkins/support/impl/NodeExecutorsTest.java

-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import static org.junit.Assert.assertNotNull;
66
import static org.junit.Assert.assertTrue;
77

8-
import com.cloudbees.jenkins.support.SafeLog;
98
import com.cloudbees.jenkins.support.SupportPlugin;
109
import com.cloudbees.jenkins.support.SupportTestUtils;
1110
import com.cloudbees.jenkins.support.filter.ContentFilter;
@@ -22,8 +21,6 @@
2221
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
2322
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
2423
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
25-
import org.junit.After;
26-
import org.junit.Before;
2724
import org.junit.ClassRule;
2825
import org.junit.Rule;
2926
import org.junit.Test;
@@ -41,16 +38,6 @@ public class NodeExecutorsTest {
4138
@ClassRule
4239
public static BuildWatcher bw = new BuildWatcher();
4340

44-
@Before
45-
public void clearLog() throws Throwable {
46-
SafeLog.clear();
47-
}
48-
49-
@After
50-
public void showLog() throws Throwable {
51-
SafeLog.show();
52-
}
53-
5441
@Test
5542
public void addContents() throws Exception {
5643
DumbSlave agent = j.createOnlineSlave(Label.parseExpression("test"), null);

src/test/java/com/cloudbees/jenkins/support/impl/NodeRemoteDirectoryComponentTest.java

+38-59
Original file line numberDiff line numberDiff line change
@@ -3,102 +3,81 @@
33
import static org.junit.Assert.assertFalse;
44
import static org.junit.Assert.assertTrue;
55

6-
import com.cloudbees.jenkins.support.SafeLog;
76
import com.cloudbees.jenkins.support.SupportTestUtils;
87
import hudson.model.Label;
98
import hudson.slaves.DumbSlave;
109
import java.util.Map;
11-
import org.junit.After;
12-
import org.junit.Before;
1310
import org.junit.Rule;
1411
import org.junit.Test;
15-
import org.jvnet.hudson.test.JenkinsSessionRule;
12+
import org.jvnet.hudson.test.JenkinsRule;
1613

1714
/**
1815
* Tests for the {@link NodeRemoteDirectoryComponent}
1916
*/
2017
public class NodeRemoteDirectoryComponentTest {
2118

2219
@Rule
23-
public JenkinsSessionRule r = new JenkinsSessionRule();
24-
25-
@Before
26-
public void clearLog() throws Throwable {
27-
SafeLog.clear();
28-
}
29-
30-
@After
31-
public void showLog() throws Throwable {
32-
SafeLog.show();
33-
}
20+
public JenkinsRule j = new JenkinsRule();
3421

3522
/*
3623
* Test adding agent remote directory content with the defaults.
3724
*/
3825
@Test
39-
public void addContents() throws Throwable {
40-
r.then(j -> {
41-
DumbSlave agent = j.createOnlineSlave(Label.parseExpression("test"), null);
26+
public void addContents() throws Exception {
27+
DumbSlave agent = j.createOnlineSlave(Label.parseExpression("test"), null);
4228

43-
Map<String, String> output =
44-
SupportTestUtils.invokeComponentToMap(new NodeRemoteDirectoryComponent(), agent.toComputer());
29+
Map<String, String> output =
30+
SupportTestUtils.invokeComponentToMap(new NodeRemoteDirectoryComponent(), agent.toComputer());
4531

46-
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
47-
assertTrue(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log")));
48-
});
32+
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
33+
assertTrue(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log")));
4934
}
5035

5136
/*
5237
* Test adding agent remote directory content with excludes pattern(s).
5338
*/
5439
@Test
55-
public void addContentsWithExcludes() throws Throwable {
56-
r.then(j -> {
57-
DumbSlave agent = j.createSlave("agent1", "test", null);
58-
agent.getComputer().connect(false).get();
59-
j.waitOnline(agent);
60-
61-
Map<String, String> output = SupportTestUtils.invokeComponentToMap(
62-
new NodeRemoteDirectoryComponent("", "**/*.log", true, 10), agent.toComputer());
63-
64-
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
65-
assertFalse(output.keySet().stream().anyMatch(key -> key.matches(prefix + ".*/.*.log")));
66-
});
40+
public void addContentsWithExcludes() throws Exception {
41+
DumbSlave agent = j.createSlave("agent1", "test", null);
42+
agent.getComputer().connect(false).get();
43+
j.waitOnline(agent);
44+
45+
Map<String, String> output = SupportTestUtils.invokeComponentToMap(
46+
new NodeRemoteDirectoryComponent("", "**/*.log", true, 10), agent.toComputer());
47+
48+
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
49+
assertFalse(output.keySet().stream().anyMatch(key -> key.matches(prefix + ".*/.*.log")));
6750
}
6851

6952
/*
7053
* Test adding agent remote directory content with includes pattern(s).
7154
*/
7255
@Test
73-
public void addContentsWithIncludes() throws Throwable {
74-
r.then(j -> {
75-
DumbSlave agent = j.createSlave("agent1", "test", null);
76-
agent.getComputer().connect(false).get();
77-
j.waitOnline(agent);
78-
79-
Map<String, String> output = SupportTestUtils.invokeComponentToMap(
80-
new NodeRemoteDirectoryComponent("support/*.log", "", true, 10), agent.toComputer());
81-
82-
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
83-
assertTrue(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log")));
84-
});
56+
public void addContentsWithIncludes() throws Exception {
57+
DumbSlave agent = j.createSlave("agent1", "test", null);
58+
agent.getComputer().connect(false).get();
59+
j.waitOnline(agent);
60+
61+
Map<String, String> output = SupportTestUtils.invokeComponentToMap(
62+
new NodeRemoteDirectoryComponent("support/*.log", "", true, 10), agent.toComputer());
63+
64+
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
65+
assertTrue(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log")));
8566
}
8667

8768
/*
8869
* Test adding agent remote directory content with includes pattern(s).
8970
*/
9071
@Test
91-
public void addContentsWithMaxDepth() throws Throwable {
92-
r.then(j -> {
93-
DumbSlave agent = j.createSlave("agent1", "test", null);
94-
agent.getComputer().connect(false).get();
95-
j.waitOnline(agent);
96-
97-
Map<String, String> output = SupportTestUtils.invokeComponentToMap(
98-
new NodeRemoteDirectoryComponent("", "", true, 1), agent.toComputer());
99-
100-
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
101-
assertFalse(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log")));
102-
});
72+
public void addContentsWithMaxDepth() throws Exception {
73+
DumbSlave agent = j.createSlave("agent1", "test", null);
74+
agent.getComputer().connect(false).get();
75+
j.waitOnline(agent);
76+
77+
Map<String, String> output = SupportTestUtils.invokeComponentToMap(
78+
new NodeRemoteDirectoryComponent("", "", true, 1), agent.toComputer());
79+
80+
String prefix = "nodes/slave/" + agent.getNodeName() + "/remote";
81+
assertFalse(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log")));
10382
}
10483
}

0 commit comments

Comments
 (0)