2017-09-07 27 views
0

爲什麼有時在Maven測試期間公共靜態AtomicBoolean變量是false?爲什麼有時在Maven測試期間公共靜態AtomicBoolean變量爲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."); 
     } 
    }//.. 
} 
} 
+0

布爾值的默認值總是'false'...您在Intellij中獲得的值是多少? –

+0

我越來越真實。 –

+1

爲什麼在獨立測試之前和期間將'isMaintenanceStarted'設置爲靜態並更改其值? Maven可以在單獨的線程中運行你的測試,並且可以在另一個線程執行你的'target.doFilter(null,null,null)'方法時執行另一個'setUp()'將'isMaintenanceStarted'設置爲false。 – tsolakp

回答

1

沒有在我的Maven的萬無一失,插件注意到

   <parallel>methods</parallel> 

相關問題