Unit tests for LoadReportClient.
| 78 | * Unit tests for {@link LoadReportClient}. |
| 79 | */ |
| 80 | @RunWith(JUnit4.class) |
| 81 | public class LoadReportClientTest { |
| 82 | // bootstrap node identifier |
| 83 | private static final EnvoyProtoData.Node NODE = |
| 84 | EnvoyProtoData.Node.newBuilder() |
| 85 | .setId("LRS test") |
| 86 | .setMetadata(ImmutableMap.of("TRAFFICDIRECTOR_NETWORK_HOSTNAME", "default")) |
| 87 | .build(); |
| 88 | private static final String CLUSTER1 = "cluster-foo.googleapis.com"; |
| 89 | private static final String CLUSTER2 = "cluster-bar.googleapis.com"; |
| 90 | private static final String EDS_SERVICE_NAME1 = "backend-service-foo.googleapis.com"; |
| 91 | private static final String EDS_SERVICE_NAME2 = "backend-service-bar.googleapis.com"; |
| 92 | private static final Locality LOCALITY1 = Locality.create("region1", "zone1", "subZone1"); |
| 93 | private static final Locality LOCALITY2 = Locality.create("region2", "zone2", "subZone2"); |
| 94 | private static final FakeClock.TaskFilter LOAD_REPORTING_TASK_FILTER = |
| 95 | new FakeClock.TaskFilter() { |
| 96 | @Override |
| 97 | public boolean shouldAccept(Runnable command) { |
| 98 | return command.toString() |
| 99 | .contains("LoadReportingTask"); |
| 100 | } |
| 101 | }; |
| 102 | private static final FakeClock.TaskFilter LRS_RPC_RETRY_TASK_FILTER = |
| 103 | new FakeClock.TaskFilter() { |
| 104 | @Override |
| 105 | public boolean shouldAccept(Runnable command) { |
| 106 | return command.toString() |
| 107 | .contains("LrsRpcRetryTask"); |
| 108 | } |
| 109 | }; |
| 110 | |
| 111 | @Rule |
| 112 | public final GrpcCleanupRule cleanupRule = new GrpcCleanupRule(); |
| 113 | @Rule |
| 114 | public final MockitoRule mocks = MockitoJUnit.rule(); |
| 115 | private final SynchronizationContext syncContext = new SynchronizationContext( |
| 116 | new Thread.UncaughtExceptionHandler() { |
| 117 | @Override |
| 118 | public void uncaughtException(Thread t, Throwable e) { |
| 119 | throw new AssertionError(e); |
| 120 | } |
| 121 | }); |
| 122 | private final FakeClock fakeClock = new FakeClock(); |
| 123 | private final ArrayDeque<StreamObserver<LoadStatsRequest>> lrsRequestObservers = |
| 124 | new ArrayDeque<>(); |
| 125 | private final AtomicBoolean callEnded = new AtomicBoolean(true); |
| 126 | private final LoadStatsManager2 loadStatsManager = |
| 127 | new LoadStatsManager2(fakeClock.getStopwatchSupplier()); |
| 128 | |
| 129 | @Mock |
| 130 | private BackoffPolicy.Provider backoffPolicyProvider; |
| 131 | @Mock |
| 132 | private BackoffPolicy backoffPolicy1; |
| 133 | @Mock |
| 134 | private BackoffPolicy backoffPolicy2; |
| 135 | @Captor |
| 136 | private ArgumentCaptor<StreamObserver<LoadStatsResponse>> lrsResponseObserverCaptor; |
| 137 | @Captor |
nothing calls this directly
no test coverage detected