mirror of https://github.com/apache/activemq.git
Fixes AMQ-6441 where a negative value can be returned with large AWS EFS files systems when calling java.io.File.getTotalSpace()
This commit is contained in:
parent
f225120f61
commit
41bec0d658
|
@ -2055,6 +2055,10 @@ public class BrokerService implements Service {
|
|||
long storeLimit = storeUsage.getLimit();
|
||||
long storeCurrent = storeUsage.getUsage();
|
||||
long totalSpace = dir.getTotalSpace();
|
||||
if (totalSpace < 0) {
|
||||
totalSpace = Long.MAX_VALUE;
|
||||
LOG.info("Total space was negative. Setting to " + totalSpace);
|
||||
}
|
||||
long totalUsableSpace = dir.getUsableSpace() + storeCurrent;
|
||||
//compute byte value of the percent limit
|
||||
long bytePercentLimit = totalSpace * percentLimit / 100;
|
||||
|
|
|
@ -315,6 +315,31 @@
|
|||
<version>${ftpserver-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito-common</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<reporting>
|
||||
|
|
|
@ -16,16 +16,29 @@
|
|||
*/
|
||||
package org.apache.activemq.broker;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.activemq.network.NetworkConnector;
|
||||
import org.apache.activemq.store.PersistenceAdapter;
|
||||
import org.apache.activemq.util.LargeFile;
|
||||
import org.apache.activemq.util.StoreUtil;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
||||
import static org.powermock.api.mockito.PowerMockito.verifyStatic;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests for the BrokerService class
|
||||
*
|
||||
* @author chirino
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(StoreUtil.class)
|
||||
public class BrokerServiceTest extends TestCase {
|
||||
|
||||
public void testAddRemoveTransportsWithJMX() throws Exception {
|
||||
BrokerService service = new BrokerService();
|
||||
service.setUseJmx(true);
|
||||
|
@ -74,11 +87,38 @@ public class BrokerServiceTest extends TestCase {
|
|||
service.stop();
|
||||
}
|
||||
|
||||
public void testSystemUsage()
|
||||
{
|
||||
public void testSystemUsage() {
|
||||
BrokerService service = new BrokerService();
|
||||
assertEquals( 1024 * 1024 * 1024, service.getSystemUsage().getMemoryUsage().getLimit() );
|
||||
assertEquals( 1024L * 1024 * 1024 * 50, service.getSystemUsage().getTempUsage().getLimit() );
|
||||
assertEquals( 1024L * 1024 * 1024 * 100, service.getSystemUsage().getStoreUsage().getLimit() );
|
||||
}
|
||||
|
||||
public void testLargeFileSystem() throws Exception {
|
||||
BrokerService service = new BrokerService();
|
||||
|
||||
File dataDirectory = new File(service.getBrokerDataDirectory(), "KahaDB");
|
||||
File tmpDataDirectory = service.getTmpDataDirectory();
|
||||
|
||||
PersistenceAdapter persistenceAdapter = service.createPersistenceAdapter();
|
||||
persistenceAdapter.setDirectory(dataDirectory);
|
||||
service.setPersistenceAdapter(persistenceAdapter);
|
||||
|
||||
mockStatic(StoreUtil.class);
|
||||
|
||||
// Return a simulated handle to a very large file system that will return a negative totalSpace.
|
||||
when(StoreUtil.findParentDirectory(dataDirectory)).thenReturn(new LargeFile(dataDirectory.getParentFile(), "KahaDB"));
|
||||
when(StoreUtil.findParentDirectory(tmpDataDirectory)).thenReturn(tmpDataDirectory);
|
||||
|
||||
service.setPersistent(false);
|
||||
service.setUseJmx(false);
|
||||
TransportConnector connector = service.addConnector("tcp://localhost:0");
|
||||
service.start();
|
||||
|
||||
service.removeConnector(connector);
|
||||
connector.stop();
|
||||
service.stop();
|
||||
|
||||
verifyStatic();
|
||||
}
|
||||
}
|
||||
|
|
25
pom.xml
25
pom.xml
|
@ -95,6 +95,7 @@
|
|||
<leveldbjni-version>1.8</leveldbjni-version>
|
||||
<log4j-version>1.2.17</log4j-version>
|
||||
<mockito-version>1.10.19</mockito-version>
|
||||
<powermock-version>1.6.5</powermock-version>
|
||||
<mqtt-client-version>1.14</mqtt-client-version>
|
||||
<openjpa-version>1.2.0</openjpa-version>
|
||||
<org-apache-derby-version>10.11.1.1</org-apache-derby-version>
|
||||
|
@ -1014,6 +1015,30 @@
|
|||
<version>${mockito-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-core</artifactId>
|
||||
<version>${powermock-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>${powermock-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>${powermock-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito-common</artifactId>
|
||||
<version>${powermock-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jmock</groupId>
|
||||
<artifactId>jmock-junit4</artifactId>
|
||||
|
|
Loading…
Reference in New Issue