Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2776 from andymc12/2880-make-in-memory-thresholds…
…-configurable [RESTEASY-2880] Config options for in-memory limit
- Loading branch information
Showing
6 changed files
with
227 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...rt/src/test/java/org/jboss/resteasy/plugins/providers/multipart/Mime4JWorkaroundTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.jboss.resteasy.plugins.providers.multipart; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class Mime4JWorkaroundTest { | ||
|
||
private static final Map<String, String> preTestProperties = new HashMap<>(); | ||
|
||
@BeforeClass | ||
public static void saveCurrentStateOfMemThresholdProperty() | ||
{ | ||
if (System.getProperties().containsKey(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY)) | ||
{ | ||
String value = System.getProperty(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY); | ||
preTestProperties.put(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY, value); | ||
} | ||
} | ||
|
||
@AfterClass | ||
public static void resetPropertiesToPreTestValues() | ||
{ | ||
if (!preTestProperties.containsKey(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY)) | ||
{ | ||
System.clearProperty(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY); | ||
} | ||
else | ||
{ | ||
preTestProperties.forEach(System::setProperty); | ||
} | ||
} | ||
|
||
@Before | ||
public void unsetMemThresholdProperty() | ||
{ | ||
System.clearProperty(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY); | ||
} | ||
|
||
@Test | ||
public void testMemThresholdDefault() | ||
{ | ||
assertEquals(Mime4JWorkaround.DEFAULT_MEM_THRESHOLD, Mime4JWorkaround.getMemThreshold()); | ||
} | ||
|
||
@Test | ||
public void testMemThresholdConfigProperty() | ||
{ | ||
System.setProperty(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY, "2048"); | ||
assertEquals(2048, Mime4JWorkaround.getMemThreshold()); | ||
} | ||
|
||
@Test | ||
public void testInvalidMemThresholdConfigPropertyReturnsDefault_NegativeNumber() | ||
{ | ||
System.setProperty(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY, "-2048"); | ||
assertEquals(Mime4JWorkaround.DEFAULT_MEM_THRESHOLD, Mime4JWorkaround.getMemThreshold()); | ||
} | ||
|
||
@Test | ||
public void testInvalidMemThresholdConfigPropertyReturnsDefault_DecimalNumber() | ||
{ | ||
System.setProperty(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY, "2048.2"); | ||
assertEquals(Mime4JWorkaround.DEFAULT_MEM_THRESHOLD, Mime4JWorkaround.getMemThreshold()); | ||
} | ||
|
||
@Test | ||
public void testInvalidMemThresholdConfigPropertyReturnsDefault_NotANumber() | ||
{ | ||
System.setProperty(Mime4JWorkaround.MEM_THRESHOLD_PROPERTY, "Infinity"); | ||
assertEquals(Mime4JWorkaround.DEFAULT_MEM_THRESHOLD, Mime4JWorkaround.getMemThreshold()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...va/org/jboss/resteasy/client/jaxrs/engines/ManualClosingApacheHttpClient43EngineTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.jboss.resteasy.client.jaxrs.engines; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.jboss.resteasy.client.jaxrs.engines.ManualClosingApacheHttpClient43Engine.FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class ManualClosingApacheHttpClient43EngineTest { | ||
|
||
private static final Map<String, String> preTestProperties = new HashMap<>(); | ||
|
||
@BeforeClass | ||
public static void saveCurrentStateOfMemThresholdProperty() | ||
{ | ||
if (System.getProperties().containsKey(FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY)) | ||
{ | ||
String value = System.getProperty(FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY); | ||
preTestProperties.put(FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY, value); | ||
} | ||
} | ||
|
||
@AfterClass | ||
public static void resetPropertiesToPreTestValues() | ||
{ | ||
if (!preTestProperties.containsKey(FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY)) | ||
{ | ||
System.clearProperty(FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY); | ||
} | ||
else | ||
{ | ||
preTestProperties.forEach(System::setProperty); | ||
} | ||
} | ||
|
||
@Before | ||
public void unsetMemThresholdProperty() | ||
{ | ||
System.clearProperty(ManualClosingApacheHttpClient43Engine.FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY); | ||
} | ||
@Test | ||
public void testMemThresholdDefault() | ||
{ | ||
assertEquals(1, new ManualClosingApacheHttpClient43Engine().getFileUploadInMemoryThresholdLimit()); | ||
} | ||
|
||
@Test | ||
public void testMemThresholdConfigProperty() | ||
{ | ||
System.setProperty(ManualClosingApacheHttpClient43Engine.FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY, "8"); | ||
assertEquals(8, new ManualClosingApacheHttpClient43Engine().getFileUploadInMemoryThresholdLimit()); | ||
} | ||
|
||
@Test | ||
public void testInvalidMemThresholdConfigPropertyReturnsDefault_NegativeNumber() | ||
{ | ||
System.setProperty(ManualClosingApacheHttpClient43Engine.FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY, "-8"); | ||
assertEquals(1, new ManualClosingApacheHttpClient43Engine().getFileUploadInMemoryThresholdLimit()); | ||
} | ||
|
||
@Test | ||
public void testInvalidMemThresholdConfigPropertyReturnsDefault_DecimalNumber() | ||
{ | ||
System.setProperty(ManualClosingApacheHttpClient43Engine.FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY, "2048.2"); | ||
assertEquals(1, new ManualClosingApacheHttpClient43Engine().getFileUploadInMemoryThresholdLimit()); | ||
} | ||
|
||
@Test | ||
public void testInvalidMemThresholdConfigPropertyReturnsDefault_NotANumber() | ||
{ | ||
System.setProperty(ManualClosingApacheHttpClient43Engine.FILE_UPLOAD_IN_MEMORY_THRESHOLD_PROPERTY, "Infinity"); | ||
assertEquals(1, new ManualClosingApacheHttpClient43Engine().getFileUploadInMemoryThresholdLimit()); | ||
} | ||
} |