|
14 | 14 |
|
15 | 15 | import java.util.Arrays; |
16 | 16 | import java.util.Map; |
| 17 | +import java.util.Set; |
17 | 18 | import java.util.concurrent.atomic.AtomicInteger; |
18 | 19 | import java.util.function.Predicate; |
19 | 20 | import java.util.stream.Collectors; |
@@ -228,6 +229,50 @@ public void testLastUsedMomentaryFeature() { |
228 | 229 | assertThat(lastUsed.get(usage), equalTo(200L)); |
229 | 230 | } |
230 | 231 |
|
| 232 | + public void testLastUsedMomentaryFeatureWithSameNameDifferentFamily() { |
| 233 | + LicensedFeature.Momentary featureFamilyA = LicensedFeature.momentary("familyA", "goldFeature", GOLD); |
| 234 | + LicensedFeature.Momentary featureFamilyB = LicensedFeature.momentary("familyB", "goldFeature", GOLD); |
| 235 | + |
| 236 | + AtomicInteger currentTime = new AtomicInteger(100); // non zero start time |
| 237 | + XPackLicenseState licenseState = new XPackLicenseState(currentTime::get); |
| 238 | + |
| 239 | + featureFamilyA.check(licenseState); |
| 240 | + featureFamilyB.check(licenseState); |
| 241 | + |
| 242 | + Map<XPackLicenseState.FeatureUsage, Long> lastUsed = licenseState.getLastUsed(); |
| 243 | + assertThat("feature.check tracks usage separately by family", lastUsed, aMapWithSize(2)); |
| 244 | + Set<FeatureInfoWithTimestamp> actualFeatures = lastUsed.entrySet() |
| 245 | + .stream() |
| 246 | + .map(it -> new FeatureInfoWithTimestamp(it.getKey().feature().getFamily(), it.getKey().feature().getName(), it.getValue())) |
| 247 | + .collect(Collectors.toSet()); |
| 248 | + assertThat( |
| 249 | + actualFeatures, |
| 250 | + containsInAnyOrder( |
| 251 | + new FeatureInfoWithTimestamp("familyA", "goldFeature", 100L), |
| 252 | + new FeatureInfoWithTimestamp("familyB", "goldFeature", 100L) |
| 253 | + ) |
| 254 | + ); |
| 255 | + |
| 256 | + currentTime.set(200); |
| 257 | + featureFamilyB.check(licenseState); |
| 258 | + |
| 259 | + lastUsed = licenseState.getLastUsed(); |
| 260 | + assertThat("feature.check tracks usage separately by family", lastUsed, aMapWithSize(2)); |
| 261 | + actualFeatures = lastUsed.entrySet() |
| 262 | + .stream() |
| 263 | + .map(it -> new FeatureInfoWithTimestamp(it.getKey().feature().getFamily(), it.getKey().feature().getName(), it.getValue())) |
| 264 | + .collect(Collectors.toSet()); |
| 265 | + assertThat( |
| 266 | + actualFeatures, |
| 267 | + containsInAnyOrder( |
| 268 | + new FeatureInfoWithTimestamp("familyA", "goldFeature", 100L), |
| 269 | + new FeatureInfoWithTimestamp("familyB", "goldFeature", 200L) |
| 270 | + ) |
| 271 | + ); |
| 272 | + } |
| 273 | + |
| 274 | + private record FeatureInfoWithTimestamp(String family, String featureName, Long timestamp) {} |
| 275 | + |
231 | 276 | public void testLastUsedPersistentFeature() { |
232 | 277 | LicensedFeature.Persistent goldFeature = LicensedFeature.persistent("family", "goldFeature", GOLD); |
233 | 278 | AtomicInteger currentTime = new AtomicInteger(100); // non zero start time |
|
0 commit comments