mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 05:22:22 +00:00
[FIXED JENKINS-15816] Run.ID_FORMATTER caches stale timezone values.
This commit is contained in:
1 parent
d4b4170010
commit
d84eca4510
4 files changed
+92
-2
No files matched your search
@@ -68,6 +68,9 @@ Upcoming changes</a>
|
||||
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15733">issue 15733</a>)
|
||||
<li class=rfe>
|
||||
Support failsafe the same way as surefire in maven2 jobs
|
||||
<li class=bug>
|
||||
Build records were broken if timezone was changed while running.
|
||||
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15816">issue 15816</a>)
|
||||
</ul>
|
||||
</div><!--=END=-->
|
||||
<h3><a name=v1.490>What's new in 1.490</a> (2012/11/12)</h3>
|
||||
|
||||
@@ -96,7 +96,6 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import jenkins.model.Jenkins;
|
||||
import jenkins.model.lazy.BuildReference;
|
||||
import jenkins.util.io.OnMaster;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.apache.commons.io.input.NullInputStream;
|
||||
@@ -240,11 +239,14 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
|
||||
*/
|
||||
private volatile transient RunExecution runner;
|
||||
|
||||
private static final SimpleDateFormat CANONICAL_ID_FORMATTER = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
|
||||
protected static final ThreadLocal<SimpleDateFormat> ID_FORMATTER =
|
||||
new ThreadLocal<SimpleDateFormat>() {
|
||||
@Override
|
||||
protected SimpleDateFormat initialValue() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
|
||||
synchronized (CANONICAL_ID_FORMATTER) {
|
||||
return (SimpleDateFormat) CANONICAL_ID_FORMATTER.clone();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright 2012 Jesse Glick.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package hudson.model;
|
||||
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import org.jvnet.hudson.test.Bug;
|
||||
|
||||
public class RunTest {
|
||||
|
||||
@Bug(15816)
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Test public void timezoneOfID() throws Exception {
|
||||
TimeZone origTZ = TimeZone.getDefault();
|
||||
try {
|
||||
final Run r;
|
||||
String id;
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago"));
|
||||
ExecutorService svc = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
r = svc.submit(new Callable<Run>() {
|
||||
@Override public Run call() throws Exception {
|
||||
return new Run(new StubJob(), 1234567890) {};
|
||||
}
|
||||
}).get();
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
id = r.getId();
|
||||
assertEquals(id, svc.submit(new Callable<String>() {
|
||||
@Override public String call() throws Exception {
|
||||
return r.getId();
|
||||
}
|
||||
}).get());
|
||||
} finally {
|
||||
svc.shutdown();
|
||||
}
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("America/New_York"));
|
||||
svc = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
assertEquals(id, r.getId());
|
||||
assertEquals(id, svc.submit(new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
return r.getId();
|
||||
}
|
||||
}).get());
|
||||
} finally {
|
||||
svc.shutdown();
|
||||
}
|
||||
} finally {
|
||||
TimeZone.setDefault(origTZ);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
package hudson.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.SortedMap;
|
||||
|
||||
/**
|
||||
@@ -55,6 +56,10 @@ class StubJob extends Job {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override protected File getBuildDir() {
|
||||
return new File(System.getProperty("java.io.tmpdir"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Override save so that nothig happens when setDisplayName() is called
|
||||
|
||||
Reference in new issue
Block a user