com.beust.jcommander.internal.Sets Java Examples

The following examples show how to use com.beust.jcommander.internal.Sets. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NodeTrackerTest.java    From osm-lib with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Check the NodeTracker against a stock Set<Long>.
 * This is done in ranges that will include numbers significantly greater than 2^32
 */
public void testAgainstSet() {
    final int N = 1000;
    // Set N numbers in each of four different ranges.
    Set<Long> numbers = Sets.newHashSet();
    NodeTracker tracker = new NodeTracker();
    for (long lo : new long[] {1L << 6, 1L << 16, 1L << 34, 1L << 50} ) {
        // Simultaneously set up a basic Set<Long> that will serve as a reference
        // and a NodeTracker that we want to test.
        long hi = 0L;
        for (int i = 0; i < 1000; i++) {
            long n = i * i + lo;
            numbers.add(n);
            tracker.add(n);
            hi = n;
        }
        // Check that the two set implementations match for every value in the range (including unset ones).
        // Note that a Set<Long> containing 0L returns false for contains((int)0).
        for (long i = lo; i < hi; i++) {
            if (tracker.contains(i)) {
                assertTrue(numbers.contains(i));
            } else {
                assertFalse(numbers.contains(i));
            }
            if (numbers.contains(i)) {
                assertTrue(tracker.contains(i));
            } else {
                assertFalse(tracker.contains(i));
            }
        }

        assertEquals(numbers.size(), tracker.cardinality());
    }
}
 
Example #2
Source File: JsonUtilsTest.java    From jolt with Apache License 2.0 5 votes vote down vote up
@BeforeClass
@SuppressWarnings("unchecked")
public void setup() throws IOException {
    jsonSource = JsonUtils.jsonToObject(jsonSourceString);
    // added for type cast checking
    Set<String> aSet = Sets.newHashSet();
    aSet.add("i");
    aSet.add("j");
    ((Map) jsonSource).put("s", aSet);
}
 
Example #3
Source File: DefaultDatabusTest.java    From emodb with Apache License 2.0 4 votes vote down vote up
@Test
public void testLazyPollResult() {
    Supplier<Condition> acceptAll = Suppliers.ofInstance(Conditions.alwaysTrue());
    TestDataProvider testDataProvider = new TestDataProvider();

    final Set<String> expectedIds = Sets.newHashSet();
    
    DatabusEventStore eventStore = mock(DatabusEventStore.class);
    when(eventStore.poll(eq("subscription"), eq(Duration.ofMinutes(1)), any(EventSink.class)))
            .thenAnswer(invocationOnMock -> {
                EventSink sink = (EventSink) invocationOnMock.getArguments()[2];
                // Return 40 updates for records from 40 unique tables
                for (int iteration = 1; iteration <= 40; iteration++) {
                    String id = "a" + iteration;
                    addToPoll(id, "table-" + iteration, "key-" + iteration, false, sink, testDataProvider);
                    expectedIds.add(id);
                }
                return false;
            });
    SubscriptionDAO subscriptionDAO = mock(SubscriptionDAO.class);
    when(subscriptionDAO.getSubscription("subscription")).thenReturn(
            new DefaultOwnedSubscription("subscription", Conditions.alwaysTrue(), new Date(1489090060000L),
                    Duration.ofSeconds(30), "owner"));

    DatabusAuthorizer databusAuthorizer = ConstantDatabusAuthorizer.ALLOW_ALL;

    // Use a clock that advances 1 second after the first call
    Clock clock = mock(Clock.class);
    when(clock.millis())
            .thenReturn(1489090000000L)
            .thenReturn(1489090001000L);

    DefaultDatabus testDatabus = new DefaultDatabus(
            mock(LifeCycleRegistry.class), mock(DatabusEventWriterRegistry.class), testDataProvider, subscriptionDAO,
            eventStore, mock(SubscriptionEvaluator.class), mock(JobService.class),
            mock(JobHandlerRegistry.class), databusAuthorizer, "systemOwnerId", acceptAll, MoreExecutors.sameThreadExecutor(),
            1, key -> 0, new MetricRegistry(), clock);

    PollResult pollResult = testDatabus.poll("owner", "subscription", Duration.ofMinutes(1), 500);
    assertFalse(pollResult.hasMoreEvents());

    Iterator<Event> events = pollResult.getEventIterator();
    Set<String> actualIds = Sets.newHashSet();
    // Read the entire event list
    while (events.hasNext()) {
        actualIds.add(events.next().getEventKey());
    }
    assertEquals(actualIds, expectedIds);
    // Events should have been loaded in 3 batches.  The first was a synchronous batch that loaded the first 10 events.
    // The seconds should have loaded 25 more events.  The third loaded the final 5 events;
    List<List<Coordinate>> executions = testDataProvider.getExecutions();
    assertEquals(executions.size(), 3);
    assertEquals(executions.get(0).size(), 10);
    assertEquals(executions.get(1).size(), 25);
    assertEquals(executions.get(2).size(), 5);
}