Java Code Examples for io.envoyproxy.envoy.api.v2.core.Node#getDefaultInstance()

The following examples show how to use io.envoyproxy.envoy.api.v2.core.Node#getDefaultInstance() . 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: CacheStatusInfoTest.java    From java-control-plane with Apache License 2.0 6 votes vote down vote up
@Test
public void watchesRemoveIfRemovesExpectedWatches() {
  final boolean ads = ThreadLocalRandom.current().nextBoolean();
  final long watchId1 = ThreadLocalRandom.current().nextLong(10000, 50000);
  final long watchId2 = ThreadLocalRandom.current().nextLong(50000, 100000);

  CacheStatusInfo<Node> info = new CacheStatusInfo<>(Node.getDefaultInstance());

  info.setWatch(watchId1, new Watch(ads, DiscoveryRequest.getDefaultInstance(), r -> { }));
  info.setWatch(watchId2, new Watch(ads, DiscoveryRequest.getDefaultInstance(), r -> { }));

  assertThat(info.numWatches()).isEqualTo(2);
  assertThat(info.watchIds()).containsExactlyInAnyOrder(watchId1, watchId2);

  info.watchesRemoveIf((watchId, watch) -> watchId.equals(watchId1));

  assertThat(info.numWatches()).isEqualTo(1);
  assertThat(info.watchIds()).containsExactlyInAnyOrder(watchId2);
}
 
Example 2
Source File: CacheStatusInfoTest.java    From java-control-plane with Apache License 2.0 6 votes vote down vote up
@Test
public void testConcurrentSetWatchAndRemove() {
  final boolean ads = ThreadLocalRandom.current().nextBoolean();
  final int watchCount = 50;

  CacheStatusInfo<Node> info = new CacheStatusInfo<>(Node.getDefaultInstance());

  Collection<Long> watchIds = LongStream.range(0, watchCount).boxed().collect(Collectors.toList());

  watchIds.parallelStream().forEach(watchId -> {
    Watch watch = new Watch(ads, DiscoveryRequest.getDefaultInstance(), r -> { });

    info.setWatch(watchId, watch);
  });

  assertThat(info.watchIds()).containsExactlyInAnyOrder(watchIds.toArray(new Long[0]));
  assertThat(info.numWatches()).isEqualTo(watchIds.size());

  watchIds.parallelStream().forEach(info::removeWatch);

  assertThat(info.watchIds()).isEmpty();
  assertThat(info.numWatches()).isZero();
}
 
Example 3
Source File: CacheStatusInfoTest.java    From java-control-plane with Apache License 2.0 4 votes vote down vote up
@Test
public void lastWatchRequestTimeReturns0IfNotSet() {
  CacheStatusInfo<Node> info = new CacheStatusInfo<>(Node.getDefaultInstance());

  assertThat(info.lastWatchRequestTime()).isZero();
}
 
Example 4
Source File: CacheStatusInfoTest.java    From java-control-plane with Apache License 2.0 4 votes vote down vote up
@Test
public void numWatchesReturnsExpectedSize() {
  final boolean ads = ThreadLocalRandom.current().nextBoolean();
  final long watchId1 = ThreadLocalRandom.current().nextLong(10000, 50000);
  final long watchId2 = ThreadLocalRandom.current().nextLong(50000, 100000);

  CacheStatusInfo<Node> info = new CacheStatusInfo<>(Node.getDefaultInstance());

  assertThat(info.numWatches()).isZero();

  info.setWatch(watchId1, new Watch(ads, DiscoveryRequest.getDefaultInstance(), r -> { }));

  assertThat(info.numWatches()).isEqualTo(1);
  assertThat(info.watchIds()).containsExactlyInAnyOrder(watchId1);

  info.setWatch(watchId2, new Watch(ads, DiscoveryRequest.getDefaultInstance(), r -> { }));

  assertThat(info.numWatches()).isEqualTo(2);
  assertThat(info.watchIds()).containsExactlyInAnyOrder(watchId1, watchId2);

  info.removeWatch(watchId1);

  assertThat(info.numWatches()).isEqualTo(1);
  assertThat(info.watchIds()).containsExactlyInAnyOrder(watchId2);
}
 
Example 5
Source File: CacheStatusInfoTest.java    From java-control-plane with Apache License 2.0 3 votes vote down vote up
@Test
public void lastWatchRequestTimeReturnsExpectedValueIfSet() {
  final long lastWatchRequestTime = ThreadLocalRandom.current().nextLong(10000, 50000);

  CacheStatusInfo<Node> info = new CacheStatusInfo<>(Node.getDefaultInstance());

  info.setLastWatchRequestTime(lastWatchRequestTime);

  assertThat(info.lastWatchRequestTime()).isEqualTo(lastWatchRequestTime);
}