forked from GoogleCloudPlatform/grpc-gcp-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGcpManagedChannelTest.java
More file actions
2232 lines (1940 loc) · 92.4 KB
/
GcpManagedChannelTest.java
File metadata and controls
2232 lines (1940 loc) · 92.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.grpc;
import static com.google.cloud.grpc.GcpManagedChannel.getKeysFromMessage;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import com.google.cloud.grpc.GcpManagedChannel.ChannelRef;
import com.google.cloud.grpc.GcpManagedChannelOptions.GcpChannelPoolOptions;
import com.google.cloud.grpc.GcpManagedChannelOptions.GcpMetricsOptions;
import com.google.cloud.grpc.GcpManagedChannelOptions.GcpResiliencyOptions;
import com.google.cloud.grpc.MetricRegistryTestUtils.FakeMetricRegistry;
import com.google.cloud.grpc.MetricRegistryTestUtils.MetricsRecord;
import com.google.cloud.grpc.MetricRegistryTestUtils.PointWithFunction;
import com.google.cloud.grpc.proto.AffinityConfig;
import com.google.cloud.grpc.proto.ApiConfig;
import com.google.cloud.grpc.proto.ChannelPoolConfig;
import com.google.cloud.grpc.proto.MethodConfig;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.spanner.v1.PartitionReadRequest;
import com.google.spanner.v1.TransactionSelector;
import io.grpc.CallOptions;
import io.grpc.ClientCall;
import io.grpc.ClientInterceptor;
import io.grpc.CompressorRegistry;
import io.grpc.ConnectivityState;
import io.grpc.DecompressorRegistry;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.MethodDescriptor;
import io.grpc.NameResolver.Factory;
import io.grpc.Status;
import io.grpc.Status.Code;
import io.opencensus.metrics.LabelKey;
import io.opencensus.metrics.LabelValue;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for GcpManagedChannel. */
@RunWith(JUnit4.class)
public final class GcpManagedChannelTest {
private static final String TARGET = "localhost";
private static final String API_FILE = "apiconfig.json";
private static final String EMPTY_METHOD_FILE = "empty_method.json";
private static final String EMPTY_CHANNEL_FILE = "empty_channel.json";
private static final int MAX_CHANNEL = 10;
private static final int MAX_STREAM = 100;
private static final Logger testLogger = Logger.getLogger(GcpManagedChannel.class.getName());
private final List<LogRecord> logRecords = new LinkedList<>();
private String lastLogMessage() {
return lastLogMessage(1);
}
private String lastLogMessage(int nthFromLast) {
return logRecords.get(logRecords.size() - nthFromLast).getMessage();
}
private Level lastLogLevel() {
return lastLogLevel(1);
}
private Level lastLogLevel(int nthFromLast) {
return logRecords.get(logRecords.size() - nthFromLast).getLevel();
}
private final Handler testLogHandler =
new Handler() {
@Override
public synchronized void publish(LogRecord record) {
logRecords.add(record);
}
@Override
public void flush() {}
@Override
public void close() throws SecurityException {}
};
private GcpManagedChannel gcpChannel;
private ManagedChannelBuilder<?> builder;
/** Close and delete all the channelRefs inside a gcpchannel. */
private void resetGcpChannel() {
gcpChannel.shutdownNow();
gcpChannel.channelRefs.clear();
}
@Before
public void setUpChannel() {
testLogger.addHandler(testLogHandler);
builder = ManagedChannelBuilder.forAddress(TARGET, 443);
gcpChannel = (GcpManagedChannel) GcpManagedChannelBuilder.forDelegateBuilder(builder).build();
}
@After
public void shutdown() {
gcpChannel.shutdownNow();
testLogger.removeHandler(testLogHandler);
testLogger.setLevel(Level.INFO);
logRecords.clear();
}
@Test
public void testLoadApiConfigFile() {
resetGcpChannel();
final URL resource = GcpManagedChannelTest.class.getClassLoader().getResource(API_FILE);
assertNotNull(resource);
File configFile = new File(resource.getFile());
gcpChannel =
(GcpManagedChannel)
GcpManagedChannelBuilder.forDelegateBuilder(builder)
.withApiConfigJsonFile(configFile)
.build();
assertEquals(0, gcpChannel.channelRefs.size());
assertEquals(3, gcpChannel.getMaxSize());
assertEquals(2, gcpChannel.getStreamsLowWatermark());
assertEquals(3, gcpChannel.methodToAffinity.size());
}
@Test
public void testLoadApiConfigString() throws Exception {
resetGcpChannel();
InputStream inputStream =
GcpManagedChannelTest.class.getClassLoader().getResourceAsStream(API_FILE);
StringBuilder sb = new StringBuilder();
assertNotNull(inputStream);
for (int ch; (ch = inputStream.read()) != -1; ) {
sb.append((char) ch);
}
gcpChannel =
(GcpManagedChannel)
GcpManagedChannelBuilder.forDelegateBuilder(builder)
.withApiConfigJsonString(sb.toString())
.build();
assertEquals(0, gcpChannel.channelRefs.size());
assertEquals(3, gcpChannel.getMaxSize());
assertEquals(2, gcpChannel.getStreamsLowWatermark());
assertEquals(3, gcpChannel.methodToAffinity.size());
}
@Test
public void testUsesPoolOptions() {
resetGcpChannel();
GcpChannelPoolOptions poolOptions =
GcpChannelPoolOptions.newBuilder()
.setMaxSize(5)
.setMinSize(2)
.setConcurrentStreamsLowWatermark(50)
.build();
GcpManagedChannelOptions options =
GcpManagedChannelOptions.newBuilder().withChannelPoolOptions(poolOptions).build();
gcpChannel =
(GcpManagedChannel)
GcpManagedChannelBuilder.forDelegateBuilder(builder).withOptions(options).build();
assertEquals(2, gcpChannel.channelRefs.size());
assertEquals(5, gcpChannel.getMaxSize());
assertEquals(2, gcpChannel.getMinSize());
assertEquals(50, gcpChannel.getStreamsLowWatermark());
}
@Test
public void testPoolOptionsOverrideApiConfig() {
resetGcpChannel();
final URL resource = GcpManagedChannelTest.class.getClassLoader().getResource(API_FILE);
assertNotNull(resource);
File configFile = new File(resource.getFile());
GcpChannelPoolOptions poolOptions =
GcpChannelPoolOptions.newBuilder()
.setMaxSize(5)
.setConcurrentStreamsLowWatermark(50)
.build();
GcpManagedChannelOptions options =
GcpManagedChannelOptions.newBuilder().withChannelPoolOptions(poolOptions).build();
gcpChannel =
(GcpManagedChannel)
GcpManagedChannelBuilder.forDelegateBuilder(builder)
.withApiConfigJsonFile(configFile)
.withOptions(options)
.build();
assertEquals(0, gcpChannel.channelRefs.size());
assertEquals(5, gcpChannel.getMaxSize());
assertEquals(50, gcpChannel.getStreamsLowWatermark());
assertEquals(3, gcpChannel.methodToAffinity.size());
}
@Test
public void testGetChannelRefInitialization() {
// Watch debug messages.
testLogger.setLevel(Level.FINER);
final int currentIndex = GcpManagedChannel.channelPoolIndex.get();
final String poolIndex = String.format("pool-%d", currentIndex);
// Initial log messages count.
int logCount = logRecords.size();
// Should not have a managedchannel by default.
assertEquals(0, gcpChannel.channelRefs.size());
// But once requested it's there.
assertEquals(0, gcpChannel.getChannelRef(null).getAffinityCount());
assertThat(logRecords.size()).isEqualTo(logCount + 2);
assertThat(lastLogMessage()).isEqualTo(poolIndex + ": Channel 0 created.");
assertThat(lastLogLevel()).isEqualTo(Level.FINER);
assertThat(logRecords.get(logRecords.size() - 2).getMessage())
.isEqualTo(poolIndex + ": Channel 0 state change detected: null -> IDLE");
assertThat(logRecords.get(logRecords.size() - 2).getLevel()).isEqualTo(Level.FINER);
// The state of this channel is idle.
assertEquals(ConnectivityState.IDLE, gcpChannel.getState(false));
assertEquals(1, gcpChannel.channelRefs.size());
}
@Test
public void testGetChannelRefInitializationWithMinSize() throws InterruptedException {
resetGcpChannel();
GcpChannelPoolOptions poolOptions =
GcpChannelPoolOptions.newBuilder().setMaxSize(5).setMinSize(2).build();
GcpManagedChannelOptions options =
GcpManagedChannelOptions.newBuilder().withChannelPoolOptions(poolOptions).build();
gcpChannel =
(GcpManagedChannel)
GcpManagedChannelBuilder.forDelegateBuilder(builder).withOptions(options).build();
// Should have 2 channels since the beginning.
assertThat(gcpChannel.channelRefs.size()).isEqualTo(2);
TimeUnit.MILLISECONDS.sleep(50);
// The connection establishment must have been started on these two channels.
assertThat(gcpChannel.getState(false))
.isAnyOf(
ConnectivityState.CONNECTING,
ConnectivityState.READY,
ConnectivityState.TRANSIENT_FAILURE);
assertThat(gcpChannel.channelRefs.get(0).getChannel().getState(false))
.isAnyOf(
ConnectivityState.CONNECTING,
ConnectivityState.READY,
ConnectivityState.TRANSIENT_FAILURE);
assertThat(gcpChannel.channelRefs.get(1).getChannel().getState(false))
.isAnyOf(
ConnectivityState.CONNECTING,
ConnectivityState.READY,
ConnectivityState.TRANSIENT_FAILURE);
}
@Test
public void testGetChannelRefPickUpSmallest() {
// All channels have max number of streams
resetGcpChannel();
for (int i = 0; i < 5; i++) {
ManagedChannel channel = builder.build();
gcpChannel.channelRefs.add(gcpChannel.new ChannelRef(channel, i, MAX_STREAM));
}
assertEquals(5, gcpChannel.channelRefs.size());
assertEquals(0, gcpChannel.getChannelRef(null).getAffinityCount());
assertEquals(6, gcpChannel.channelRefs.size());
// Add more channels, the smallest stream value is -1 with idx 6.
int[] streams = new int[] {-1, 5, 7, 1};
for (int i = 6; i < 10; i++) {
ManagedChannel channel = builder.build();
gcpChannel.channelRefs.add(gcpChannel.new ChannelRef(channel, i, streams[i - 6]));
}
assertEquals(10, gcpChannel.channelRefs.size());
assertEquals(6, gcpChannel.getChannelRef(null).getAffinityCount());
}
@Test
public void testNewKeyBindingsSpreadAcrossIdleChannels() {
// Regression: when all activeStreamsCounts are equal (e.g., a burst of new
// affinity keys arriving before any GcpClientCall.start() runs), bindings
// should spread across channels rather than collapsing onto index 0.
resetGcpChannel();
final int numChannels = 8;
for (int i = 0; i < numChannels; i++) {
gcpChannel.channelRefs.add(gcpChannel.new ChannelRef(builder.build(), i, 0));
}
Set<ChannelRef> picked = new HashSet<>();
for (int i = 0; i < 64; i++) {
picked.add(gcpChannel.getChannelRef("k" + i));
}
assertThat(picked).hasSize(numChannels);
}
private void assertFallbacksMetric(
FakeMetricRegistry fakeRegistry, long successes, long failures) {
MetricsRecord record = fakeRegistry.pollRecord();
List<PointWithFunction<?>> metric =
record.getMetrics().get(GcpMetricsConstants.METRIC_NUM_FALLBACKS);
assertThat(metric.size()).isEqualTo(2);
assertThat(metric.get(0).value()).isEqualTo(successes);
assertThat(metric.get(0).values().get(0))
.isEqualTo(LabelValue.create(GcpMetricsConstants.RESULT_SUCCESS));
assertThat(metric.get(1).value()).isEqualTo(failures);
assertThat(metric.get(1).values().get(0))
.isEqualTo(LabelValue.create(GcpMetricsConstants.RESULT_ERROR));
}
@Test
public void testGetChannelRefWithFallback() {
// Watch debug messages.
testLogger.setLevel(Level.FINEST);
final FakeMetricRegistry fakeRegistry = new FakeMetricRegistry();
final int maxSize = 3;
final int lowWatermark = 2;
// Creating a pool with fallback, max size and low watermark above.
final GcpManagedChannel pool =
(GcpManagedChannel)
GcpManagedChannelBuilder.forDelegateBuilder(builder)
.withApiConfig(
ApiConfig.newBuilder()
.setChannelPool(
ChannelPoolConfig.newBuilder()
.setMaxSize(maxSize)
.setMaxConcurrentStreamsLowWatermark(lowWatermark)
.build())
.build())
.withOptions(
GcpManagedChannelOptions.newBuilder()
.withResiliencyOptions(
GcpResiliencyOptions.newBuilder().setNotReadyFallback(true).build())
.withMetricsOptions(
GcpMetricsOptions.newBuilder().withMetricRegistry(fakeRegistry).build())
.build())
.build();
final int currentIndex = GcpManagedChannel.channelPoolIndex.get();
final String poolIndex = String.format("pool-%d", currentIndex);
// Creates the first channel with 0 id.
assertEquals(0, pool.getNumberOfChannels());
ChannelRef chRef = pool.getChannelRef(null);
assertEquals(0, chRef.getId());
assertEquals(1, pool.getNumberOfChannels());
// The 0 channel is ready by default, so the subsequent request for a channel should return
// the 0 channel again if its active streams (currently 0) are less than the low watermark.
chRef = pool.getChannelRef(null);
assertEquals(0, chRef.getId());
assertEquals(1, pool.getNumberOfChannels());
// Let's simulate the non-ready state for the 0 channel.
pool.processChannelStateChange(0, ConnectivityState.CONNECTING);
int logCount = logRecords.size();
// Now request for a channel should return a newly created channel because our current channel
// is not ready, and we haven't reached the pool's max size.
chRef = pool.getChannelRef(null);
assertEquals(1, chRef.getId());
assertEquals(2, pool.getNumberOfChannels());
// This was a fallback from non-ready channel 0 to the newly created channel 1.
assertThat(logRecords.size()).isEqualTo(logCount + 3);
assertThat(lastLogMessage()).isEqualTo(poolIndex + ": Fallback to newly created channel 1");
assertThat(lastLogLevel()).isEqualTo(Level.FINEST);
assertFallbacksMetric(fakeRegistry, 1, 0);
// Adding one active stream to channel 1.
pool.channelRefs.get(1).activeStreamsCountIncr();
logCount = logRecords.size();
// Having 0 active streams on channel 0 and 1 active streams on channel one with the default
// settings would return channel 0 for the next channel request. But having fallback enabled and
// channel 0 not ready it should return channel 1 instead.
chRef = pool.getChannelRef(null);
assertEquals(1, chRef.getId());
assertEquals(2, pool.getNumberOfChannels());
// This was the second fallback from non-ready channel 0 to the channel 1.
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogMessage()).isEqualTo(poolIndex + ": Picking fallback channel: 0 -> 1");
assertThat(lastLogLevel()).isEqualTo(Level.FINEST);
assertFallbacksMetric(fakeRegistry, 2, 0);
// Now let's have channel 0 still as not ready but bring channel 1 streams to low watermark.
for (int i = 0; i < lowWatermark - 1; i++) {
pool.channelRefs.get(1).activeStreamsCountIncr();
}
// Having one non-ready channel and another channel reached the low watermark should create a
// new channel for the next channel request if we haven't reached max size.
chRef = pool.getChannelRef(null);
assertEquals(2, chRef.getId());
assertEquals(3, pool.getNumberOfChannels());
// Now we reached max pool size. Let's bring channel 2 to the low watermark and channel 1 to the
// low watermark + 1 streams.
for (int i = 0; i < lowWatermark; i++) {
pool.channelRefs.get(2).activeStreamsCountIncr();
}
pool.channelRefs.get(1).activeStreamsCountIncr();
// As we reached max size and cannot create new channels and having ready channels with low
// watermark and low watermark + 1 streams, the best channel for the next channel request with
// the fallback enabled is the channel 2 with low watermark streams because it's the least busy
// ready channel.
assertEquals(lowWatermark + 1, pool.channelRefs.get(1).getActiveStreamsCount());
assertEquals(lowWatermark, pool.channelRefs.get(2).getActiveStreamsCount());
chRef = pool.getChannelRef(null);
assertEquals(2, chRef.getId());
assertEquals(3, pool.getNumberOfChannels());
// This was the third fallback from non-ready channel 0 to the channel 2.
assertFallbacksMetric(fakeRegistry, 3, 0);
// Let's bring channel 1 to max streams and mark channel 2 as not ready.
for (int i = 0; i < MAX_STREAM - lowWatermark; i++) {
pool.channelRefs.get(2).activeStreamsCountIncr();
}
pool.processChannelStateChange(1, ConnectivityState.CONNECTING);
assertEquals(MAX_STREAM, pool.channelRefs.get(2).getActiveStreamsCount());
// Now we have two non-ready channels and one overloaded.
// Even when fallback enabled there is no good candidate at this time, the next channel request
// should return a channel with the lowest streams count regardless of its readiness state.
// In our case it is channel 0.
logCount = logRecords.size();
chRef = pool.getChannelRef(null);
assertEquals(0, chRef.getId());
assertEquals(3, pool.getNumberOfChannels());
// This will also count as a failed fallback because we couldn't find a ready and non-overloaded
// channel.
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogMessage()).isEqualTo(poolIndex + ": Failed to find fallback for channel 0");
assertThat(lastLogLevel()).isEqualTo(Level.FINEST);
assertFallbacksMetric(fakeRegistry, 3, 1);
// Let's have an affinity key and bind it to channel 0.
final String key = "ABC";
pool.bind(pool.channelRefs.get(0), Collections.singletonList(key));
logCount = logRecords.size();
// Channel 0 is not ready currently and the fallback enabled should look for a fallback but we
// still don't have a good channel because channel 1 is not ready and channel 2 is overloaded.
// The getChannelRef should return the original channel 0 and report a failed fallback.
chRef = pool.getChannelRef(key);
assertEquals(0, chRef.getId());
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogMessage()).isEqualTo(poolIndex + ": Failed to find fallback for channel 0");
assertThat(lastLogLevel()).isEqualTo(Level.FINEST);
assertFallbacksMetric(fakeRegistry, 3, 2);
// Let's return channel 1 to a ready state.
pool.processChannelStateChange(1, ConnectivityState.READY);
logCount = logRecords.size();
// Now we have a fallback candidate.
// The getChannelRef should return the channel 1 and report a successful fallback.
chRef = pool.getChannelRef(key);
assertEquals(1, chRef.getId());
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogMessage()).isEqualTo(poolIndex + ": Setting fallback channel: 0 -> 1");
assertThat(lastLogLevel()).isEqualTo(Level.FINEST);
assertFallbacksMetric(fakeRegistry, 4, 2);
// Let's briefly bring channel 2 to ready state.
pool.processChannelStateChange(2, ConnectivityState.READY);
logCount = logRecords.size();
// Now we have a better fallback candidate (fewer streams on channel 2). But this time we
// already used channel 1 as a fallback, and we should stick to it instead of returning the
// original channel.
// The getChannelRef should return the channel 1 and report a successful fallback.
chRef = pool.getChannelRef(key);
assertEquals(1, chRef.getId());
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogMessage()).isEqualTo(poolIndex + ": Using fallback channel: 0 -> 1");
assertThat(lastLogLevel()).isEqualTo(Level.FINEST);
assertFallbacksMetric(fakeRegistry, 5, 2);
pool.processChannelStateChange(2, ConnectivityState.CONNECTING);
// Let's bring channel 1 back to connecting state.
pool.processChannelStateChange(1, ConnectivityState.CONNECTING);
logCount = logRecords.size();
// Now we don't have a good fallback candidate again. But this time we already used channel 1
// as a fallback and we should stick to it instead of returning the original channel.
// The getChannelRef should return the channel 1 and report a failed fallback.
chRef = pool.getChannelRef(key);
assertEquals(1, chRef.getId());
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogMessage()).isEqualTo(poolIndex + ": Failed to find fallback for channel 0");
assertThat(lastLogLevel()).isEqualTo(Level.FINEST);
assertFallbacksMetric(fakeRegistry, 5, 3);
// Finally, we bring both channel 1 and channel 0 to the ready state and we should get the
// original channel 0 for the key without any fallbacks happening.
pool.processChannelStateChange(1, ConnectivityState.READY);
pool.processChannelStateChange(0, ConnectivityState.READY);
logCount = logRecords.size();
chRef = pool.getChannelRef(key);
assertEquals(0, chRef.getId());
assertThat(logRecords.size()).isEqualTo(logCount);
assertFallbacksMetric(fakeRegistry, 5, 3);
}
@Test
public void testGetChannelRefMaxSize() {
resetGcpChannel();
for (int i = 0; i < MAX_CHANNEL; i++) {
ManagedChannel channel = builder.build();
gcpChannel.channelRefs.add(gcpChannel.new ChannelRef(channel, i, MAX_STREAM));
}
assertEquals(MAX_CHANNEL, gcpChannel.channelRefs.size());
assertEquals(MAX_STREAM, gcpChannel.getChannelRef(null).getActiveStreamsCount());
assertEquals(MAX_CHANNEL, gcpChannel.channelRefs.size());
}
@Test
public void testBindUnbindKey() {
// Watch debug messages.
testLogger.setLevel(Level.FINEST);
final int currentIndex = GcpManagedChannel.channelPoolIndex.get();
final String poolIndex = String.format("pool-%d", currentIndex);
// Initialize the channel and bind the key, check the affinity count.
gcpChannel.nextChannelId.set(1);
ChannelRef cf1 = gcpChannel.new ChannelRef(builder.build(), 0, 5);
ChannelRef cf2 = gcpChannel.new ChannelRef(builder.build(), 0, 4);
gcpChannel.channelRefs.add(cf1);
gcpChannel.channelRefs.add(cf2);
gcpChannel.bind(cf1, Collections.singletonList("key1"));
// Initial log messages count.
int logCount = logRecords.size();
gcpChannel.bind(cf2, Collections.singletonList("key2"));
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogMessage()).isEqualTo(poolIndex + ": Binding 1 key(s) to channel 2: [key2]");
assertThat(lastLogLevel()).isEqualTo(Level.FINEST);
gcpChannel.bind(cf2, Collections.singletonList("key3"));
// Binding the same key to the same channel should not increase affinity count.
gcpChannel.bind(cf1, Collections.singletonList("key1"));
assertEquals(1, gcpChannel.channelRefs.get(0).getAffinityCount());
assertEquals(2, gcpChannel.channelRefs.get(1).getAffinityCount());
assertEquals(3, gcpChannel.affinityKeyToChannelRef.size());
// Binding the same key to a different channel should alter affinity counts accordingly.
gcpChannel.bind(cf1, Collections.singletonList("key3"));
assertEquals(2, gcpChannel.channelRefs.get(0).getAffinityCount());
assertEquals(1, gcpChannel.channelRefs.get(1).getAffinityCount());
assertEquals(3, gcpChannel.affinityKeyToChannelRef.size());
logCount = logRecords.size();
// Unbind the affinity key.
gcpChannel.unbind(Collections.singletonList("key1"));
assertEquals(1, gcpChannel.channelRefs.get(0).getAffinityCount());
assertEquals(1, gcpChannel.channelRefs.get(1).getAffinityCount());
assertEquals(2, gcpChannel.affinityKeyToChannelRef.size());
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogMessage()).isEqualTo(poolIndex + ": Unbinding key key1 from channel 1.");
assertThat(lastLogLevel()).isEqualTo(Level.FINEST);
gcpChannel.unbind(Collections.singletonList("key1"));
assertEquals(1, gcpChannel.channelRefs.get(0).getAffinityCount());
assertEquals(1, gcpChannel.channelRefs.get(1).getAffinityCount());
assertEquals(2, gcpChannel.affinityKeyToChannelRef.size());
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogMessage()).isEqualTo(poolIndex + ": Unbinding key key1 but it wasn't bound.");
assertThat(lastLogLevel()).isEqualTo(Level.FINEST);
gcpChannel.unbind(Collections.singletonList("key2"));
assertEquals(1, gcpChannel.channelRefs.get(0).getAffinityCount());
assertEquals(0, gcpChannel.channelRefs.get(1).getAffinityCount());
assertEquals(1, gcpChannel.affinityKeyToChannelRef.size());
gcpChannel.unbind(Collections.singletonList("key3"));
assertEquals(0, gcpChannel.channelRefs.get(0).getAffinityCount());
assertEquals(0, gcpChannel.channelRefs.get(1).getAffinityCount());
assertEquals(0, gcpChannel.affinityKeyToChannelRef.size());
}
@Test
public void testUsingKeyWithoutBinding() {
// Initialize the channel and bind the key, check the affinity count.
gcpChannel.nextChannelId.set(1);
ChannelRef cf1 = gcpChannel.new ChannelRef(builder.build(), 0, 5);
ChannelRef cf2 = gcpChannel.new ChannelRef(builder.build(), 0, 4);
gcpChannel.channelRefs.add(cf1);
gcpChannel.channelRefs.add(cf2);
final String key = "non-binded-key";
ChannelRef channelRef = gcpChannel.getChannelRef(key);
// Should bind on the fly to the least busy channel, which is 2.
assertThat(channelRef.getId()).isEqualTo(2);
cf1.activeStreamsCountDecr(System.nanoTime(), Status.OK, true);
cf1.activeStreamsCountDecr(System.nanoTime(), Status.OK, true);
channelRef = gcpChannel.getChannelRef(key);
// Even after channel 1 now has less active streams (3) the channel 2 is still mapped for the
// same key.
assertThat(channelRef.getId()).isEqualTo(2);
}
@Test
public void testGetKeysFromRequest() {
String expected = "thisisaname";
TransactionSelector selector = TransactionSelector.getDefaultInstance();
PartitionReadRequest req =
PartitionReadRequest.newBuilder()
.setSession(expected)
.setTable("jenny")
.setTransaction(selector)
.addColumns("users")
.build();
List<String> result = getKeysFromMessage(req, "session");
assertEquals(expected, result.get(0));
result = getKeysFromMessage(req, "fakesession");
assertEquals(0, result.size());
}
@Test
public void testParseGoodJsonFile() {
final URL resource = GcpManagedChannelTest.class.getClassLoader().getResource(API_FILE);
assertNotNull(resource);
File configFile = new File(resource.getFile());
ApiConfig apiconfig =
GcpManagedChannelBuilder.forDelegateBuilder(builder)
.withApiConfigJsonFile(configFile)
.apiConfig;
ChannelPoolConfig expectedChannel =
ChannelPoolConfig.newBuilder().setMaxSize(3).setMaxConcurrentStreamsLowWatermark(2).build();
Assert.assertEquals(expectedChannel, apiconfig.getChannelPool());
assertEquals(3, apiconfig.getMethodCount());
MethodConfig.Builder expectedMethod1 = MethodConfig.newBuilder();
expectedMethod1.addName("google.spanner.v1.Spanner/CreateSession");
expectedMethod1.setAffinity(
AffinityConfig.newBuilder()
.setAffinityKey("name")
.setCommand(AffinityConfig.Command.BIND)
.build());
assertEquals(expectedMethod1.build(), apiconfig.getMethod(0));
MethodConfig.Builder expectedMethod2 = MethodConfig.newBuilder();
expectedMethod2.addName("google.spanner.v1.Spanner/GetSession");
expectedMethod2.setAffinity(
AffinityConfig.newBuilder()
.setAffinityKey("name")
.setCommand(AffinityConfig.Command.BOUND)
.build());
assertEquals(expectedMethod2.build(), apiconfig.getMethod(1));
MethodConfig.Builder expectedMethod3 = MethodConfig.newBuilder();
expectedMethod3.addName("google.spanner.v1.Spanner/DeleteSession");
expectedMethod3.setAffinity(
AffinityConfig.newBuilder()
.setAffinityKey("name")
.setCommand(AffinityConfig.Command.UNBIND)
.build());
assertEquals(expectedMethod3.build(), apiconfig.getMethod(2));
}
@Test
public void testParseEmptyMethodJsonFile() {
final URL resource =
GcpManagedChannelTest.class.getClassLoader().getResource(EMPTY_METHOD_FILE);
assertNotNull(resource);
File configFile = new File(resource.getFile());
ApiConfig apiconfig =
GcpManagedChannelBuilder.forDelegateBuilder(builder)
.withApiConfigJsonFile(configFile)
.apiConfig;
ChannelPoolConfig expectedChannel =
ChannelPoolConfig.newBuilder()
.setMaxSize(5)
.setIdleTimeout(1000)
.setMaxConcurrentStreamsLowWatermark(5)
.build();
Assert.assertEquals(expectedChannel, apiconfig.getChannelPool());
assertEquals(0, apiconfig.getMethodCount());
}
@Test
public void testParseEmptyChannelJsonFile() {
final URL resource =
GcpManagedChannelTest.class.getClassLoader().getResource(EMPTY_CHANNEL_FILE);
assertNotNull(resource);
File configFile = new File(resource.getFile());
ApiConfig apiconfig =
GcpManagedChannelBuilder.forDelegateBuilder(builder)
.withApiConfigJsonFile(configFile)
.apiConfig;
Assert.assertEquals(ChannelPoolConfig.getDefaultInstance(), apiconfig.getChannelPool());
assertEquals(3, apiconfig.getMethodCount());
MethodConfig.Builder expectedMethod1 = MethodConfig.newBuilder();
expectedMethod1.addName("/google.spanner.v1.Spanner/CreateSession");
expectedMethod1.setAffinity(
AffinityConfig.newBuilder()
.setAffinityKey("name")
.setCommand(AffinityConfig.Command.BIND)
.build());
assertEquals(expectedMethod1.build(), apiconfig.getMethod(0));
MethodConfig.Builder expectedMethod2 = MethodConfig.newBuilder();
expectedMethod2.addName("/google.spanner.v1.Spanner/GetSession").addName("additional name");
expectedMethod2.setAffinity(
AffinityConfig.newBuilder()
.setAffinityKey("name")
.setCommand(AffinityConfig.Command.BOUND)
.build());
assertEquals(expectedMethod2.build(), apiconfig.getMethod(1));
assertEquals(MethodConfig.getDefaultInstance(), apiconfig.getMethod(2));
}
@Test
public void testMetrics() {
// Watch debug messages.
testLogger.setLevel(Level.FINE);
final FakeMetricRegistry fakeRegistry = new FakeMetricRegistry();
final String prefix = "some/prefix/";
final List<LabelKey> labelKeys =
Arrays.asList(LabelKey.create("key_a", ""), LabelKey.create("key_b", ""));
final List<LabelValue> labelValues =
Arrays.asList(LabelValue.create("val_a"), LabelValue.create("val_b"));
final GcpManagedChannel pool =
(GcpManagedChannel)
GcpManagedChannelBuilder.forDelegateBuilder(builder)
.withApiConfig(
ApiConfig.newBuilder()
.setChannelPool(
ChannelPoolConfig.newBuilder()
.setMaxConcurrentStreamsLowWatermark(1)
.build())
.build())
.withOptions(
GcpManagedChannelOptions.newBuilder()
.withMetricsOptions(
GcpMetricsOptions.newBuilder()
.withMetricRegistry(fakeRegistry)
.withNamePrefix(prefix)
.withLabels(labelKeys, labelValues)
.build())
.build())
.build();
final int currentIndex = GcpManagedChannel.channelPoolIndex.get();
final String poolIndex = String.format("pool-%d", currentIndex);
// Logs metrics options.
assertThat(logRecords.get(logRecords.size() - 2).getLevel()).isEqualTo(Level.FINE);
assertThat(logRecords.get(logRecords.size() - 2).getMessage())
.startsWith(
poolIndex
+ ": Metrics options: {namePrefix: \"some/prefix/\", labels: "
+ "[key_a: \"val_a\", key_b: \"val_b\"],");
assertThat(lastLogLevel()).isEqualTo(Level.INFO);
assertThat(lastLogMessage()).isEqualTo(poolIndex + ": Metrics enabled (OpenCensus).");
List<LabelKey> expectedLabelKeys = new ArrayList<>(labelKeys);
expectedLabelKeys.add(
LabelKey.create(GcpMetricsConstants.POOL_INDEX_LABEL, GcpMetricsConstants.POOL_INDEX_DESC));
List<LabelValue> expectedLabelValues = new ArrayList<>(labelValues);
expectedLabelValues.add(LabelValue.create(poolIndex));
try {
// Let's fill five channels with some fake streams.
int[] streams = new int[] {3, 2, 5, 7, 1};
for (int count : streams) {
ChannelRef ref = pool.getChannelRef(null);
for (int j = 0; j < count; j++) {
ref.activeStreamsCountIncr();
}
}
MetricsRecord record = fakeRegistry.pollRecord();
assertThat(record.getMetrics().size()).isEqualTo(28);
// Initial log messages count.
int logCount = logRecords.size();
List<PointWithFunction<?>> minChannels =
record.getMetrics().get(prefix + GcpMetricsConstants.METRIC_MIN_CHANNELS);
assertThat(minChannels.size()).isEqualTo(1);
assertThat(minChannels.get(0).value()).isEqualTo(0L);
assertThat(minChannels.get(0).keys()).isEqualTo(expectedLabelKeys);
assertThat(minChannels.get(0).values()).isEqualTo(expectedLabelValues);
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogLevel()).isEqualTo(Level.FINE);
assertThat(lastLogMessage())
.isEqualTo(poolIndex + ": stat: " + GcpMetricsConstants.METRIC_MIN_CHANNELS + " = 0");
List<PointWithFunction<?>> maxChannels =
record.getMetrics().get(prefix + GcpMetricsConstants.METRIC_MAX_CHANNELS);
assertThat(maxChannels.size()).isEqualTo(1);
assertThat(maxChannels.get(0).value()).isEqualTo(5L);
assertThat(maxChannels.get(0).keys()).isEqualTo(expectedLabelKeys);
assertThat(maxChannels.get(0).values()).isEqualTo(expectedLabelValues);
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogLevel()).isEqualTo(Level.FINE);
assertThat(lastLogMessage())
.isEqualTo(poolIndex + ": stat: " + GcpMetricsConstants.METRIC_MAX_CHANNELS + " = 5");
List<PointWithFunction<?>> numChannels =
record.getMetrics().get(prefix + GcpMetricsConstants.METRIC_NUM_CHANNELS);
assertThat(numChannels.size()).isEqualTo(1);
assertThat(numChannels.get(0).value()).isEqualTo(5L);
assertThat(numChannels.get(0).keys()).isEqualTo(expectedLabelKeys);
assertThat(numChannels.get(0).values()).isEqualTo(expectedLabelValues);
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogLevel()).isEqualTo(Level.FINE);
assertThat(lastLogMessage())
.isEqualTo(poolIndex + ": stat: " + GcpMetricsConstants.METRIC_NUM_CHANNELS + " = 5");
List<PointWithFunction<?>> maxAllowedChannels =
record.getMetrics().get(prefix + GcpMetricsConstants.METRIC_MAX_ALLOWED_CHANNELS);
assertThat(maxAllowedChannels.size()).isEqualTo(1);
assertThat(maxAllowedChannels.get(0).value()).isEqualTo(MAX_CHANNEL);
assertThat(maxAllowedChannels.get(0).keys()).isEqualTo(expectedLabelKeys);
assertThat(maxAllowedChannels.get(0).values()).isEqualTo(expectedLabelValues);
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogLevel()).isEqualTo(Level.FINE);
assertThat(lastLogMessage())
.isEqualTo(
poolIndex + ": stat: " + GcpMetricsConstants.METRIC_MAX_ALLOWED_CHANNELS + " = 10");
List<PointWithFunction<?>> minActiveStreams =
record.getMetrics().get(prefix + GcpMetricsConstants.METRIC_MIN_ACTIVE_STREAMS);
assertThat(minActiveStreams.size()).isEqualTo(1);
assertThat(minActiveStreams.get(0).value()).isEqualTo(0L);
assertThat(minActiveStreams.get(0).keys()).isEqualTo(expectedLabelKeys);
assertThat(minActiveStreams.get(0).values()).isEqualTo(expectedLabelValues);
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogLevel()).isEqualTo(Level.FINE);
assertThat(lastLogMessage())
.isEqualTo(
poolIndex + ": stat: " + GcpMetricsConstants.METRIC_MIN_ACTIVE_STREAMS + " = 0");
List<PointWithFunction<?>> maxActiveStreams =
record.getMetrics().get(prefix + GcpMetricsConstants.METRIC_MAX_ACTIVE_STREAMS);
assertThat(maxActiveStreams.size()).isEqualTo(1);
assertThat(maxActiveStreams.get(0).value()).isEqualTo(7L);
assertThat(maxActiveStreams.get(0).keys()).isEqualTo(expectedLabelKeys);
assertThat(maxActiveStreams.get(0).values()).isEqualTo(expectedLabelValues);
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogLevel()).isEqualTo(Level.FINE);
assertThat(lastLogMessage())
.isEqualTo(
poolIndex + ": stat: " + GcpMetricsConstants.METRIC_MAX_ACTIVE_STREAMS + " = 7");
List<PointWithFunction<?>> totalActiveStreams =
record.getMetrics().get(prefix + GcpMetricsConstants.METRIC_MAX_TOTAL_ACTIVE_STREAMS);
assertThat(totalActiveStreams.size()).isEqualTo(1);
long totalStreamsExpected = Arrays.stream(streams).asLongStream().sum();
assertThat(totalActiveStreams.get(0).value()).isEqualTo(totalStreamsExpected);
assertThat(totalActiveStreams.get(0).keys()).isEqualTo(expectedLabelKeys);
assertThat(totalActiveStreams.get(0).values()).isEqualTo(expectedLabelValues);
assertThat(logRecords.size()).isEqualTo(++logCount);
assertThat(lastLogLevel()).isEqualTo(Level.FINE);
assertThat(lastLogMessage())
.isEqualTo(
poolIndex
+ ": stat: "
+ GcpMetricsConstants.METRIC_MAX_TOTAL_ACTIVE_STREAMS
+ " = "
+ totalStreamsExpected);
} finally {
pool.shutdownNow();
}
}
@Test
public void testLogMetrics() throws InterruptedException {
// Watch debug messages.
testLogger.setLevel(Level.FINE);
int[] streams = new int[] {3, 2, 5, 7, 1};
int[] keyCount = new int[] {2, 3, 1, 1, 4};
int[] okCalls = new int[] {2, 2, 8, 2, 3};
int[] errCalls = new int[] {1, 1, 2, 2, 1};
List<FakeManagedChannel> channels = new ArrayList<>();
ExecutorService executorService = Executors.newSingleThreadExecutor();
for (int i = 0; i < streams.length; i++) {
FakeManagedChannel channel = new FakeManagedChannel(executorService);
channels.add(channel);
}
final GcpManagedChannel pool =
(GcpManagedChannel)
GcpManagedChannelBuilder.forDelegateBuilder(new FakeManagedChannelBuilder(channels))
.withOptions(
GcpManagedChannelOptions.newBuilder()
.withChannelPoolOptions(
GcpChannelPoolOptions.newBuilder()
.setMaxSize(5)
.setConcurrentStreamsLowWatermark(3)
.build())
.withMetricsOptions(
GcpMetricsOptions.newBuilder().withNamePrefix("prefix").build())
.withResiliencyOptions(
GcpResiliencyOptions.newBuilder()
.setNotReadyFallback(true)
.withUnresponsiveConnectionDetection(100, 2)
.build())
.build())
.build();
try {
final int currentIndex = GcpManagedChannel.channelPoolIndex.get();
final String poolIndex = String.format("pool-%d", currentIndex);
for (int i = 0; i < streams.length; i++) {
ChannelRef ref = pool.createNewChannel();
// Simulate channel connecting.
channels.get(i).setState(ConnectivityState.CONNECTING);
TimeUnit.MILLISECONDS.sleep(10);
// For the last one...
if (i == streams.length - 1) {
// This will be a couple of successful fallbacks.
pool.getChannelRef(null);
pool.getChannelRef(null);
// Bring down all other channels.
for (int j = 0; j < i; j++) {
channels.get(j).setState(ConnectivityState.CONNECTING);
}
TimeUnit.MILLISECONDS.sleep(100);
// And this will be a failed fallback (no ready channels).
pool.getChannelRef(null);
// Simulate unresponsive connection.
long startNanos = System.nanoTime();
final Status deStatus = Status.fromCode(Code.DEADLINE_EXCEEDED);
ref.activeStreamsCountIncr();
ref.activeStreamsCountDecr(startNanos, deStatus, false);
ref.activeStreamsCountIncr();
ref.activeStreamsCountDecr(startNanos, deStatus, false);
// Simulate unresponsive connection with more dropped calls.
startNanos = System.nanoTime();
ref.activeStreamsCountIncr();
ref.activeStreamsCountDecr(startNanos, deStatus, false);
ref.activeStreamsCountIncr();
ref.activeStreamsCountDecr(startNanos, deStatus, false);
TimeUnit.MILLISECONDS.sleep(110);
ref.activeStreamsCountIncr();
ref.activeStreamsCountDecr(startNanos, deStatus, false);
}
channels.get(i).setState(ConnectivityState.READY);
for (int j = 0; j < streams[i]; j++) {
ref.activeStreamsCountIncr();
}
// Bind affinity keys.
final List<String> keys = new ArrayList<>();
for (int j = 0; j < keyCount[i]; j++) {
keys.add("key-" + i + "-" + j);
}
pool.bind(ref, keys);
// Simulate successful calls.
for (int j = 0; j < okCalls[i]; j++) {
ref.activeStreamsCountDecr(0, Status.OK, false);
ref.activeStreamsCountIncr();