为什么 public static AtomicBoolean 变量有时在 Maven 中的测试期间为 false?
Why public static AtomicBoolean variable is false during the test in Maven sometimes?
为什么 public static AtomicBoolean 变量有时在 Maven 中的测试期间为 false?
也许,粗鲁的并发错误?
但在 Intellij 中工作正常。
public class MaintenanceFilterTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
private MaintenanceFilter target;
@Before
public void setUp() throws Exception {
target = new MaintenanceFilter();
MaintenanceFilter.isMaintenanceStarted.set(false);
}
@Test
public void doFilterException() throws Exception {
MaintenanceFilter.isMaintenanceStarted.set(true);
expectedException.expect(MaintenanceException.class);
expectedException.expectMessage
("Redeployment of application or restart of server is in progress.");
target.doFilter(null, null, null);
}
public static class MaintenanceFilter implements Filter {
public static final AtomicBoolean isMaintenanceStarted = new AtomicBoolean();
@Override
public void doFilter(
ServletRequest input,
ServletResponse output,
FilterChain chain
) throws IOException,
ServletException {
if (isMaintenanceStarted.get()) {
throw new MaintenanceException
("Redeployment of application or restart of server is in progress.");
}
}//..
}
}
没注意到
<parallel>methods</parallel>
在我的 maven-surefire-plugin 中。
为什么 public static AtomicBoolean 变量有时在 Maven 中的测试期间为 false?
也许,粗鲁的并发错误?
但在 Intellij 中工作正常。
public class MaintenanceFilterTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
private MaintenanceFilter target;
@Before
public void setUp() throws Exception {
target = new MaintenanceFilter();
MaintenanceFilter.isMaintenanceStarted.set(false);
}
@Test
public void doFilterException() throws Exception {
MaintenanceFilter.isMaintenanceStarted.set(true);
expectedException.expect(MaintenanceException.class);
expectedException.expectMessage
("Redeployment of application or restart of server is in progress.");
target.doFilter(null, null, null);
}
public static class MaintenanceFilter implements Filter {
public static final AtomicBoolean isMaintenanceStarted = new AtomicBoolean();
@Override
public void doFilter(
ServletRequest input,
ServletResponse output,
FilterChain chain
) throws IOException,
ServletException {
if (isMaintenanceStarted.get()) {
throw new MaintenanceException
("Redeployment of application or restart of server is in progress.");
}
}//..
}
}
没注意到
<parallel>methods</parallel>
在我的 maven-surefire-plugin 中。