UnionFakeSubscriptionSelector implements FakeSubscriptionSelector { @Override public ObjectsPair<Collection<LiveDataSpecification>, Collection<LiveDataSpecification>> splitShouldFake( FakeSubscriptionBloombergLiveDataServer server, Collection<LiveDataSpecification> uniqueIds) { Collection<LiveDataSpecification> real = uniqueIds; Set<LiveDataSpecification> fakes = new HashSet<LiveDataSpecification>(); for (FakeSubscriptionSelector subSelector : _fakeSubscriptionSelectors) { ObjectsPair<Collection<LiveDataSpecification>, Collection<LiveDataSpecification>> split = subSelector.splitShouldFake(server, real); real = split.first; fakes.addAll(split.second); if (real.isEmpty()) { break; } } return ObjectsPair.of(real, (Collection<LiveDataSpecification>) fakes); } UnionFakeSubscriptionSelector(FakeSubscriptionSelector... fakeSubscriptionSelectors); @Override ObjectsPair<Collection<LiveDataSpecification>, Collection<LiveDataSpecification>> splitShouldFake(
      FakeSubscriptionBloombergLiveDataServer server, Collection<LiveDataSpecification> uniqueIds);  }
@Test public void splitCorrectly() throws Exception { final ArrayList<String> queries = Lists.newArrayList("BPSW13 Curncy", "USPL30RK Curncy", "AAPL US 01/21/12 C145 Equity" ); ByTypeFakeSubscriptionSelector swapVol = new ByTypeFakeSubscriptionSelector("SWAPTION VOLATILITY"); ByTypeFakeSubscriptionSelector fxOptionVol = new ByTypeFakeSubscriptionSelector("SWAP"); UnionFakeSubscriptionSelector union = new UnionFakeSubscriptionSelector(swapVol, fxOptionVol); ByTypeFakeSubscriptionSelector alternateUnion = new ByTypeFakeSubscriptionSelector("SWAPTION VOLATILITY", "SWAP"); ObjectsPair<Collection<LiveDataSpecification>, Collection<LiveDataSpecification>> splitShouldFake = union.splitShouldFake(_server, getSpecs(queries)); assertEquals(queries.size(), splitShouldFake.first.size() + splitShouldFake.second.size()); ObjectsPair<Collection<LiveDataSpecification>, Collection<LiveDataSpecification>> splitShouldFakeAlt = alternateUnion.splitShouldFake(_server, getSpecs(queries)); assertEquals(splitShouldFake.first, splitShouldFakeAlt.first); assertEquals(splitShouldFake.second, splitShouldFakeAlt.second); }
@Test public void splitEconomicallyInOrder() throws Exception { final ByTypeFakeSubscriptionSelector swap = new ByTypeFakeSubscriptionSelector("SWAP"); FakeSubscriptionSelector noSwaps = new FakeSubscriptionSelector() { @Override public ObjectsPair<Collection<LiveDataSpecification>, Collection<LiveDataSpecification>> splitShouldFake( FakeSubscriptionBloombergLiveDataServer server, Collection<LiveDataSpecification> uniqueIds) { assertTrue(swap.splitShouldFake(server, uniqueIds).second.isEmpty()); return ObjectsPair.of((Collection<LiveDataSpecification>) new HashSet<LiveDataSpecification>(), uniqueIds); } }; ByTypeFakeSubscriptionSelector swaptionVol = new ByTypeFakeSubscriptionSelector("SWAPTION VOLATILITY "); FakeSubscriptionSelector throwing = new FakeSubscriptionSelector() { @Override public ObjectsPair<Collection<LiveDataSpecification>, Collection<LiveDataSpecification>> splitShouldFake( FakeSubscriptionBloombergLiveDataServer server, Collection<LiveDataSpecification> uniqueIds) { throw new IllegalArgumentException(); } }; UnionFakeSubscriptionSelector union = new UnionFakeSubscriptionSelector(swap, noSwaps, swaptionVol, throwing); Collection<String> queries = Sets.newHashSet("BPSW13 Curncy", "USPL30RK Curncy"); ObjectsPair<Collection<LiveDataSpecification>, Collection<LiveDataSpecification>> splitShouldFake = union.splitShouldFake(_server, getSpecs(queries)); assertEquals(Sets.newHashSet(), splitShouldFake.first); assertEquals(queries.size(), splitShouldFake.second.size()); }
@Test public void splitBrokenWorks() { final ArrayList<String> queries = Lists.newArrayList("USSV15F Curncy", "USPL30RK Curncy" ); ByTypeFakeSubscriptionSelector swapVol = new ByTypeFakeSubscriptionSelector("SWAPTION VOLATILITY"); ByTypeFakeSubscriptionSelector fxOptionVol = new ByTypeFakeSubscriptionSelector("SWAP"); UnionFakeSubscriptionSelector union = new UnionFakeSubscriptionSelector(swapVol, fxOptionVol); ObjectsPair<Collection<LiveDataSpecification>, Collection<LiveDataSpecification>> splitShouldFake = union.splitShouldFake(_server, getSpecs(queries)); assertEquals(queries.size(), splitShouldFake.first.size() + splitShouldFake.second.size()); assertEquals(1, splitShouldFake.first.size()); assertEquals(1, splitShouldFake.second.size()); }