|
18 | 18 |
|
19 | 19 | import static org.junit.Assert.*;
|
20 | 20 |
|
21 |
| -import java.util.Properties; |
22 |
| - |
23 | 21 | import org.junit.Test;
|
24 | 22 |
|
25 | 23 | import io.reactivex.TestHelper;
|
26 |
| -import io.reactivex.internal.schedulers.SchedulerPoolFactory.PurgeProperties; |
| 24 | +import io.reactivex.functions.Function; |
| 25 | +import io.reactivex.internal.functions.Functions; |
27 | 26 | import io.reactivex.schedulers.Schedulers;
|
28 | 27 |
|
29 | 28 | public class SchedulerPoolFactoryTest {
|
@@ -78,53 +77,66 @@ public void run() {
|
78 | 77 | }
|
79 | 78 |
|
80 | 79 | @Test
|
81 |
| - public void loadPurgeProperties() { |
82 |
| - Properties props1 = new Properties(); |
83 |
| - |
84 |
| - PurgeProperties pp = new PurgeProperties(); |
85 |
| - pp.load(props1); |
86 |
| - |
87 |
| - assertTrue(pp.purgeEnable); |
88 |
| - assertEquals(pp.purgePeriod, 1); |
| 80 | + public void boolPropertiesDisabledReturnsDefaultDisabled() throws Throwable { |
| 81 | + assertTrue(SchedulerPoolFactory.getBooleanProperty(false, "key", false, true, failingPropertiesAccessor)); |
| 82 | + assertFalse(SchedulerPoolFactory.getBooleanProperty(false, "key", true, false, failingPropertiesAccessor)); |
89 | 83 | }
|
90 | 84 |
|
91 | 85 | @Test
|
92 |
| - public void loadPurgePropertiesDisabled() { |
93 |
| - Properties props1 = new Properties(); |
94 |
| - props1.setProperty(SchedulerPoolFactory.PURGE_ENABLED_KEY, "false"); |
| 86 | + public void boolPropertiesEnabledMissingReturnsDefaultMissing() throws Throwable { |
| 87 | + assertTrue(SchedulerPoolFactory.getBooleanProperty(true, "key", true, false, missingPropertiesAccessor)); |
| 88 | + assertFalse(SchedulerPoolFactory.getBooleanProperty(true, "key", false, true, missingPropertiesAccessor)); |
| 89 | + } |
95 | 90 |
|
96 |
| - PurgeProperties pp = new PurgeProperties(); |
97 |
| - pp.load(props1); |
| 91 | + @Test |
| 92 | + public void boolPropertiesFailureReturnsDefaultMissing() throws Throwable { |
| 93 | + assertTrue(SchedulerPoolFactory.getBooleanProperty(true, "key", true, false, failingPropertiesAccessor)); |
| 94 | + assertFalse(SchedulerPoolFactory.getBooleanProperty(true, "key", false, true, failingPropertiesAccessor)); |
| 95 | + } |
98 | 96 |
|
99 |
| - assertFalse(pp.purgeEnable); |
100 |
| - assertEquals(pp.purgePeriod, 1); |
| 97 | + @Test |
| 98 | + public void boolPropertiesReturnsValue() throws Throwable { |
| 99 | + assertTrue(SchedulerPoolFactory.getBooleanProperty(true, "true", true, false, Functions.<String>identity())); |
| 100 | + assertFalse(SchedulerPoolFactory.getBooleanProperty(true, "false", false, true, Functions.<String>identity())); |
101 | 101 | }
|
102 | 102 |
|
103 | 103 | @Test
|
104 |
| - public void loadPurgePropertiesEnabledCustomPeriod() { |
105 |
| - Properties props1 = new Properties(); |
106 |
| - props1.setProperty(SchedulerPoolFactory.PURGE_ENABLED_KEY, "true"); |
107 |
| - props1.setProperty(SchedulerPoolFactory.PURGE_PERIOD_SECONDS_KEY, "2"); |
| 104 | + public void intPropertiesDisabledReturnsDefaultDisabled() throws Throwable { |
| 105 | + assertEquals(-1, SchedulerPoolFactory.getIntProperty(false, "key", 0, -1, failingPropertiesAccessor)); |
| 106 | + assertEquals(-1, SchedulerPoolFactory.getIntProperty(false, "key", 1, -1, failingPropertiesAccessor)); |
| 107 | + } |
108 | 108 |
|
109 |
| - PurgeProperties pp = new PurgeProperties(); |
110 |
| - pp.load(props1); |
| 109 | + @Test |
| 110 | + public void intPropertiesEnabledMissingReturnsDefaultMissing() throws Throwable { |
| 111 | + assertEquals(-1, SchedulerPoolFactory.getIntProperty(true, "key", -1, 0, missingPropertiesAccessor)); |
| 112 | + assertEquals(-1, SchedulerPoolFactory.getIntProperty(true, "key", -1, 1, missingPropertiesAccessor)); |
| 113 | + } |
111 | 114 |
|
112 |
| - assertTrue(pp.purgeEnable); |
113 |
| - assertEquals(pp.purgePeriod, 2); |
| 115 | + @Test |
| 116 | + public void intPropertiesFailureReturnsDefaultMissing() throws Throwable { |
| 117 | + assertEquals(-1, SchedulerPoolFactory.getIntProperty(true, "key", -1, 0, failingPropertiesAccessor)); |
| 118 | + assertEquals(-1, SchedulerPoolFactory.getIntProperty(true, "key", -1, 1, failingPropertiesAccessor)); |
114 | 119 | }
|
115 | 120 |
|
116 | 121 | @Test
|
117 |
| - public void loadPurgePropertiesEnabledCustomPeriodNaN() { |
118 |
| - Properties props1 = new Properties(); |
119 |
| - props1.setProperty(SchedulerPoolFactory.PURGE_ENABLED_KEY, "true"); |
120 |
| - props1.setProperty(SchedulerPoolFactory.PURGE_PERIOD_SECONDS_KEY, "abc"); |
| 122 | + public void intPropertiesReturnsValue() throws Throwable { |
| 123 | + assertEquals(1, SchedulerPoolFactory.getIntProperty(true, "1", 0, 4, Functions.<String>identity())); |
| 124 | + assertEquals(2, SchedulerPoolFactory.getIntProperty(true, "2", 3, 5, Functions.<String>identity())); |
| 125 | + } |
121 | 126 |
|
122 |
| - PurgeProperties pp = new PurgeProperties(); |
123 |
| - pp.load(props1); |
| 127 | + static final Function<String, String> failingPropertiesAccessor = new Function<String, String>() { |
| 128 | + @Override |
| 129 | + public String apply(String v) throws Exception { |
| 130 | + throw new SecurityException(); |
| 131 | + } |
| 132 | + }; |
124 | 133 |
|
125 |
| - assertTrue(pp.purgeEnable); |
126 |
| - assertEquals(pp.purgePeriod, 1); |
127 |
| - } |
| 134 | + static final Function<String, String> missingPropertiesAccessor = new Function<String, String>() { |
| 135 | + @Override |
| 136 | + public String apply(String v) throws Exception { |
| 137 | + return null; |
| 138 | + } |
| 139 | + }; |
128 | 140 |
|
129 | 141 | @Test
|
130 | 142 | public void putIntoPoolNoPurge() {
|
|
0 commit comments