@@ -565,7 +565,7 @@ public void attributesWork() {
565
565
);
566
566
567
567
assertEquals ("on" , client .getTreatment ("adil@codigo.com" , test ));
568
- assertEquals ("on" , client .getTreatment ("adil@codigo.com" , test , null ));
568
+ assertEquals ("on" , client .getTreatment ("adil@codigo.com" , test , new HashMap <>() ));
569
569
assertEquals ("on" , client .getTreatment ("adil@codigo.com" , test , ImmutableMap .<String , Object >of ()));
570
570
assertEquals ("on" , client .getTreatment ("pato@codigo.com" , test , ImmutableMap .<String , Object >of ("age" , 10 )));
571
571
assertEquals ("off" , client .getTreatment ("pato@codigo.com" , test , ImmutableMap .<String , Object >of ("age" , 9 )));
@@ -599,7 +599,7 @@ public void attributesWork2() {
599
599
);
600
600
601
601
assertEquals ("off" , client .getTreatment ("adil@codigo.com" , test ));
602
- assertEquals ("off" , client .getTreatment ("adil@codigo.com" , test , null ));
602
+ assertEquals ("off" , client .getTreatment ("adil@codigo.com" , test , new HashMap <>() ));
603
603
assertEquals ("off" , client .getTreatment ("adil@codigo.com" , test , ImmutableMap .<String , Object >of ()));
604
604
605
605
assertEquals ("off" , client .getTreatment ("pato@codigo.com" , test , ImmutableMap .<String , Object >of ("age" , 10 )));
@@ -634,7 +634,7 @@ public void attributesGreaterThanNegativeNumber() {
634
634
);
635
635
636
636
assertEquals ("off" , client .getTreatment ("adil@codigo.com" , test ));
637
- assertEquals ("off" , client .getTreatment ("adil@codigo.com" , test , null ));
637
+ assertEquals ("off" , client .getTreatment ("adil@codigo.com" , test , new HashMap <>() ));
638
638
assertEquals ("off" , client .getTreatment ("adil@codigo.com" , test , ImmutableMap .<String , Object >of ()));
639
639
assertEquals ("off" , client .getTreatment ("pato@codigo.com" , test , ImmutableMap .<String , Object >of ("age" , 10 )));
640
640
assertEquals ("on" , client .getTreatment ("pato@codigo.com" , test , ImmutableMap .<String , Object >of ("age" , -20 )));
@@ -671,7 +671,7 @@ public void attributesForSets() {
671
671
);
672
672
673
673
assertEquals ("off" , client .getTreatment ("adil@codigo.com" , test ));
674
- assertEquals ("off" , client .getTreatment ("adil@codigo.com" , test , null ));
674
+ assertEquals ("off" , client .getTreatment ("adil@codigo.com" , test , new HashMap <>() ));
675
675
676
676
assertEquals ("off" , client .getTreatment ("adil@codigo.com" , test , ImmutableMap .<String , Object >of ()));
677
677
assertEquals ("off" , client .getTreatment ("pato@codigo.com" , test , ImmutableMap .<String , Object >of ("products" , Lists .newArrayList ())));
@@ -1486,6 +1486,7 @@ public void worksAndHasConfigByFlagSetTryKetTreatmentWithKey() {
1486
1486
assertEquals ("on" , client .getTreatmentsByFlagSet (randomKey , "set1" , new HashMap <>()).get (test ));
1487
1487
assertEquals ("{\" size\" : 30}" , client .getTreatmentsWithConfigByFlagSet (key , "set1" , attributes ).get (test ).config ());
1488
1488
}
1489
+ assertEquals ("on" , client .getTreatmentsByFlagSet ("randomKey" , "set1" ).get (test ));
1489
1490
}
1490
1491
1491
1492
@ Test
@@ -1894,11 +1895,13 @@ public void testTreatmentsByFlagSet() {
1894
1895
Map <String , String > getTreatmentResult ;
1895
1896
for (int i = 0 ; i < numKeys ; i ++) {
1896
1897
String randomKey = RandomStringUtils .random (10 );
1897
- getTreatmentResult = client .getTreatmentsByFlagSet (randomKey , "set1" , null );
1898
+ getTreatmentResult = client .getTreatmentsByFlagSet (randomKey , "set1" , new HashMap <>() );
1898
1899
assertEquals ("on" , getTreatmentResult .get (test ));
1899
1900
}
1900
1901
verify (splitCacheConsumer , times (numKeys )).fetchMany (new ArrayList <>(Arrays .asList (test )));
1901
1902
verify (TELEMETRY_STORAGE , times (5 )).recordLatency (Mockito .anyObject (), Mockito .anyLong ());
1903
+ getTreatmentResult = client .getTreatmentsByFlagSet ("randomKey" , "set1" );
1904
+ assertEquals ("on" , getTreatmentResult .get (test ));
1902
1905
}
1903
1906
1904
1907
@ Test
@@ -1927,7 +1930,7 @@ public void testTreatmentsByFlagSetInvalid() {
1927
1930
new EvaluatorImp (splitCacheConsumer , segmentCacheConsumer ), TELEMETRY_STORAGE , TELEMETRY_STORAGE ,
1928
1931
flagSetsFilter
1929
1932
);
1930
- assertTrue (client .getTreatmentsByFlagSet (RandomStringUtils .random (10 ), "" , null ).isEmpty ());
1933
+ assertTrue (client .getTreatmentsByFlagSet (RandomStringUtils .random (10 ), "" , new HashMap <>() ).isEmpty ());
1931
1934
}
1932
1935
1933
1936
@ Test
@@ -1974,12 +1977,15 @@ public void testTreatmentsByFlagSets() {
1974
1977
Map <String , String > getTreatmentResult ;
1975
1978
for (int i = 0 ; i < numKeys ; i ++) {
1976
1979
String randomKey = RandomStringUtils .random (10 );
1977
- getTreatmentResult = client .getTreatmentsByFlagSets (randomKey , Arrays .asList ("set1" , "set3" ), null );
1980
+ getTreatmentResult = client .getTreatmentsByFlagSets (randomKey , Arrays .asList ("set1" , "set3" ), new HashMap <>() );
1978
1981
assertEquals ("on" , getTreatmentResult .get (test ));
1979
1982
assertEquals ("on" , getTreatmentResult .get (test2 ));
1980
1983
}
1981
1984
verify (splitCacheConsumer , times (numKeys )).fetchMany (new ArrayList <>(Arrays .asList (test2 , test )));
1982
1985
verify (TELEMETRY_STORAGE , times (5 )).recordLatency (Mockito .anyObject (), Mockito .anyLong ());
1986
+ getTreatmentResult = client .getTreatmentsByFlagSets ("key" , Arrays .asList ("set1" , "set3" ));
1987
+ assertEquals ("on" , getTreatmentResult .get (test ));
1988
+ assertEquals ("on" , getTreatmentResult .get (test2 ));
1983
1989
}
1984
1990
1985
1991
@ Test
@@ -2030,6 +2036,12 @@ public void treatmentsWorksAndHasConfigFlagSet() {
2030
2036
assertEquals ("control" , result .get (test2 ).treatment ());
2031
2037
2032
2038
verify (splitCacheConsumer , times (1 )).fetchMany (anyList ());
2039
+
2040
+ result = client .getTreatmentsWithConfigByFlagSet ("randomKey" , "set1" );
2041
+ assertEquals (2 , result .size ());
2042
+ assertEquals (configurations .get ("on" ), result .get (test ).config ());
2043
+ assertNull (result .get (test2 ).config ());
2044
+ assertEquals ("control" , result .get (test2 ).treatment ());
2033
2045
}
2034
2046
2035
2047
@ Test
@@ -2081,4 +2093,89 @@ public void treatmentsWorksAndHasConfigFlagSets() {
2081
2093
2082
2094
verify (splitCacheConsumer , times (1 )).fetchMany (anyList ());
2083
2095
}
2096
+
2097
+ @ Test
2098
+ public void impressionPropertiesTest () {
2099
+ String test = "test1" ;
2100
+
2101
+ ParsedCondition age_equal_to_0_should_be_on = new ParsedCondition (ConditionType .ROLLOUT ,
2102
+ CombiningMatcher .of ("age" , new EqualToMatcher (-20 , DataType .NUMBER )),
2103
+ Lists .newArrayList (partition ("on" , 100 )),
2104
+ "foolabel"
2105
+ );
2106
+
2107
+ List <ParsedCondition > conditions = Lists .newArrayList (age_equal_to_0_should_be_on );
2108
+ ParsedSplit parsedSplit = ParsedSplit .createParsedSplitForTests (test , 123 , false , Treatments .OFF , conditions , null , 1 , 1 , new HashSet <>(Arrays .asList ("set" )), true );
2109
+ Map <String , ParsedSplit > parsedSplits = new HashMap <>();
2110
+ parsedSplits .put (test , parsedSplit );
2111
+
2112
+ SplitCacheConsumer splitCacheConsumer = mock (SplitCacheConsumer .class );
2113
+ SegmentCacheConsumer segmentCacheConsumer = mock (SegmentCacheConsumer .class );
2114
+ when (splitCacheConsumer .get (test )).thenReturn (parsedSplit );
2115
+ when (splitCacheConsumer .fetchMany (Arrays .asList (test ))).thenReturn (parsedSplits );
2116
+ Map <String , HashSet <String >> splits = new HashMap <>();
2117
+ splits .put ("set" , new HashSet <>(Arrays .asList (test )));
2118
+ when (splitCacheConsumer .getNamesByFlagSets (Arrays .asList ("set" ))).thenReturn (splits );
2119
+
2120
+ SDKReadinessGates gates = mock (SDKReadinessGates .class );
2121
+ ImpressionsManager impressionsManager = mock (ImpressionsManager .class );
2122
+ SplitClientImpl client = new SplitClientImpl (
2123
+ mock (SplitFactory .class ),
2124
+ splitCacheConsumer ,
2125
+ impressionsManager ,
2126
+ NoopEventsStorageImp .create (),
2127
+ config ,
2128
+ gates ,
2129
+ new EvaluatorImp (splitCacheConsumer , segmentCacheConsumer ), TELEMETRY_STORAGE , TELEMETRY_STORAGE ,
2130
+ new FlagSetsFilterImpl (new HashSet <>())
2131
+ );
2132
+ Map <String , Object > attributes = ImmutableMap .<String , Object >of ("age" , -20 , "acv" , "1000000" );
2133
+ EvaluationOptions properties = new EvaluationOptions (new HashMap <String , Object >()
2134
+ {{
2135
+ put ("prop2" , "val2" );
2136
+ put ("prop1" , "val1" );
2137
+ }});
2138
+ Map <String , String > result = new HashMap <>();
2139
+ result .put (test , Treatments .ON );
2140
+ List <String > split_names = Arrays .asList (test );
2141
+
2142
+ assertEquals ("on" , client .getTreatment ("pato@codigo.com" , test , attributes , properties ));
2143
+ assertEquals ("on" , client .getTreatmentWithConfig ("bilal1@codigo.com" , test , attributes , properties ).treatment ());
2144
+ assertEquals ("on" , client .getTreatments ("bilal2@codigo.com" , Arrays .asList (test ), attributes , properties ).get (test ));
2145
+ assertEquals ("on" , client .getTreatmentsWithConfig ("bilal3@codigo.com" , Arrays .asList (test ), attributes , properties ).get (test ).treatment ());
2146
+ assertEquals ("on" , client .getTreatmentsByFlagSet ("bilal4@codigo.com" , "set" , attributes , properties ).get (test ));
2147
+ assertEquals ("on" , client .getTreatmentsByFlagSets ("bilal5@codigo.com" , Arrays .asList ("set" ), attributes , properties ).get (test ));
2148
+ assertEquals ("on" , client .getTreatmentsWithConfigByFlagSet ("bilal6@codigo.com" , "set" , attributes , properties ).get (test ).treatment ());
2149
+ assertEquals ("on" , client .getTreatmentsWithConfigByFlagSets ("bilal7@codigo.com" , Arrays .asList ("set" ), attributes , properties ).get (test ).treatment ());
2150
+ assertEquals ("on" , client .getTreatment (new Key ("bilal8@codigo.com" , "bilal8@codigo.com" ), test , attributes , properties ));
2151
+ assertEquals ("on" , client .getTreatmentWithConfig (new Key ("bilal9@codigo.com" , "bilal9@codigo.com" ), test , attributes , properties ).treatment ());
2152
+ assertEquals ("on" , client .getTreatments (new Key ("bilal10@codigo.com" , "bilal10@codigo.com" ), Arrays .asList (test ), attributes , properties ).get (test ));
2153
+ assertEquals ("on" , client .getTreatmentsWithConfig (new Key ("bilal11@codigo.com" , "bilal11@codigo.com" ), Arrays .asList (test ), attributes , properties ).get (test ).treatment ());
2154
+ assertEquals ("on" , client .getTreatmentsByFlagSet (new Key ("bilal12@codigo.com" , "bilal12@codigo.com" ), "set" , attributes , properties ).get (test ));
2155
+ assertEquals ("on" , client .getTreatmentsByFlagSets (new Key ("bilal13@codigo.com" , "bilal13@codigo.com" ), Arrays .asList ("set" ), attributes , properties ).get (test ));
2156
+ assertEquals ("on" , client .getTreatmentsWithConfigByFlagSet (new Key ("bilal14@codigo.com" , "bilal14@codigo.com" ), "set" , attributes , properties ).get (test ).treatment ());
2157
+ assertEquals ("on" , client .getTreatmentsWithConfigByFlagSets (new Key ("bilal15@codigo.com" , "bilal15@codigo.com" ), Arrays .asList ("set" ), attributes , properties ).get (test ).treatment ());
2158
+ assertEquals ("off" , client .getTreatment ("bilal16@codigo.com" , test , properties ));
2159
+ assertEquals ("off" , client .getTreatmentWithConfig ("bilal17@codigo.com" , test , properties ).treatment ());
2160
+ assertEquals ("off" , client .getTreatments ("bilal18@codigo.com" , Arrays .asList (test ), properties ).get (test ));
2161
+ assertEquals ("off" , client .getTreatmentsWithConfig ("bilal19@codigo.com" , Arrays .asList (test ), properties ).get (test ).treatment ());
2162
+ assertEquals ("off" , client .getTreatmentsByFlagSet ("bilal20@codigo.com" , "set" , properties ).get (test ));
2163
+ assertEquals ("off" , client .getTreatmentsByFlagSets ("bilal21@codigo.com" , Arrays .asList ("set" ), properties ).get (test ));
2164
+ assertEquals ("off" , client .getTreatmentsWithConfigByFlagSet ("bilal22@codigo.com" , "set" , properties ).get (test ).treatment ());
2165
+ assertEquals ("off" , client .getTreatmentsWithConfigByFlagSets ("bilal23@codigo.com" , Arrays .asList ("set" ), properties ).get (test ).treatment ());
2166
+
2167
+ ArgumentCaptor <List > impressionCaptor = ArgumentCaptor .forClass (List .class );
2168
+ verify (impressionsManager , times (24 )).track (impressionCaptor .capture ());
2169
+ assertNotNull (impressionCaptor .getValue ());
2170
+
2171
+ DecoratedImpression impression = (DecoratedImpression ) impressionCaptor .getAllValues ().get (0 ).get (0 );
2172
+ assertEquals ("pato@codigo.com" , impression .impression ().key ());
2173
+ assertEquals ("{\" prop2\" :\" val2\" ,\" prop1\" :\" val1\" }" , impression .impression ().properties ());
2174
+
2175
+ for (int i =1 ; i <=23 ; i ++) {
2176
+ impression = (DecoratedImpression ) impressionCaptor .getAllValues ().get (i ).get (0 );
2177
+ assertEquals ("bilal" + i + "@codigo.com" , impression .impression ().key ());
2178
+ assertEquals ("{\" prop2\" :\" val2\" ,\" prop1\" :\" val1\" }" , impression .impression ().properties ());
2179
+ }
2180
+ }
2084
2181
}
0 commit comments