|
29 | 29 | import java.util.Collections; |
30 | 30 | import java.util.HashSet; |
31 | 31 | import java.util.List; |
| 32 | +import java.util.Map; |
| 33 | +import java.util.Optional; |
32 | 34 | import java.util.Set; |
33 | 35 | import org.dcache.cells.UniversalSpringCell; |
34 | 36 | import org.dcache.pool.classic.IoQueueManager; |
@@ -151,7 +153,37 @@ public void testGsonDeserialization() throws Exception { |
151 | 153 | .disableHtmlEscaping().create().toJson(obj); |
152 | 154 | } |
153 | 155 |
|
| 156 | + @Test |
| 157 | + public void testWritePoolZonePreference() throws Exception { |
| 158 | + prepareCostModule(false, true); |
| 159 | + |
| 160 | + FileAttributes attributes = FileAttributes.of().pnfsId(_pnfsId).build(); |
| 161 | + StorageInfos.injectInto(_storageInfo, attributes); |
| 162 | + |
| 163 | + PoolSelector selector = _poolMonitor.getPoolSelector(attributes, _protocolInfo, |
| 164 | + null, Optional.of("1"), Collections.EMPTY_SET); |
| 165 | + |
| 166 | + assertEquals("pool1", selector.selectWritePool(0).name()); |
| 167 | + } |
| 168 | + |
| 169 | + @Test |
| 170 | + public void testReadPoolZonePreference() throws Exception { |
| 171 | + prepareCostModule(false, true); |
| 172 | + |
| 173 | + FileAttributes attributes = FileAttributes.of().pnfsId(_pnfsId).locations(_pools).build(); |
| 174 | + StorageInfos.injectInto(_storageInfo, attributes); |
| 175 | + |
| 176 | + PoolSelector selector = _poolMonitor.getPoolSelector(attributes, _protocolInfo, |
| 177 | + null, Optional.of("1"), Collections.EMPTY_SET); |
| 178 | + |
| 179 | + assertEquals("pool1", selector.selectReadPool().name()); |
| 180 | + } |
| 181 | + |
154 | 182 | private void prepareCostModule(boolean linkPerPool) throws Exception { |
| 183 | + prepareCostModule(linkPerPool, false); |
| 184 | + } |
| 185 | + |
| 186 | + private void prepareCostModule(boolean linkPerPool, boolean withZones) throws Exception { |
155 | 187 | if (linkPerPool) { |
156 | 188 | PoolMonitorHelper.prepareLinkPerPool(_selectionUnit, _access, _pools); |
157 | 189 | } else { |
@@ -179,6 +211,11 @@ private void prepareCostModule(boolean linkPerPool) throws Exception { |
179 | 211 | pool1UpMessage.setHostName(_localhost); |
180 | 212 | pool2UpMessage.setHostName(_localhost); |
181 | 213 |
|
| 214 | + if (withZones) { |
| 215 | + pool1UpMessage.setTagMap(Map.of("zone", "1")); |
| 216 | + pool2UpMessage.setTagMap(Map.of("zone", "2")); |
| 217 | + } |
| 218 | + |
182 | 219 | CellMessage envelope1 = new CellMessage(new CellAddressCore("PoolManager"), null); |
183 | 220 | envelope1.addSourceAddress(new CellAddressCore("pool1")); |
184 | 221 | CellMessage envelope2 = new CellMessage(new CellAddressCore("PoolManager"), null); |
|
0 commit comments