77package com .azure .cosmos ;
88
99import com .azure .cosmos .SuperFlakyTestRetryAnalyzer ;
10+ import com .azure .cosmos .implementation .DefaultCosmosItemSerializer ;
1011import com .azure .cosmos .implementation .ImplementationBridgeHelpers ;
1112import com .azure .cosmos .implementation .InternalObjectNode ;
1213import com .azure .cosmos .implementation .OverridableRequestOptions ;
1314import com .azure .cosmos .implementation .TestConfigurations ;
15+ import com .azure .cosmos .implementation .Utils ;
1416import com .azure .cosmos .models .CosmosBatch ;
1517import com .azure .cosmos .models .CosmosBatchResponse ;
1618import com .azure .cosmos .models .CosmosBulkExecutionOptions ;
@@ -79,8 +81,11 @@ public class OperationPoliciesTest extends TestSuiteBase {
7981 private static final String MAX_PREFETCH_PAGE_COUNT = "maxPrefetchPageCount" ;
8082 private static final String QUERY_NAME = "queryName" ;
8183 private static final String KEYWORD_IDENTIFIERS = "keywordIdentifiers" ;
82- private static final String [] optionLabels = {E2E_TIMEOUT , CONSISTENCY_LEVEL , CONTENT_RESPONSE_ON_WRITE , NON_IDEMPOTENT_WRITE_RETRIES , BYPASS_CACHE , THROUGHPUT_CONTROL_GROUP_NAME , REQUEST_CHARGE_THRESHOLD , SCAN_IN_QUERY , EXCLUDE_REGIONS , MAX_DEGREE_OF_PARALLELISM , MAX_BUFFERED_ITEM_COUNT , RESPONSE_CONTINUATION_TOKEN_LIMIT_KB , MAX_ITEM_COUNT , QUERY_METRICS , INDEX_METRICS , MAX_PREFETCH_PAGE_COUNT , QUERY_NAME , KEYWORD_IDENTIFIERS , READ_CONSISTENCY_STRATEGY };
83- private static final String [] initialOptions = {"20" , "Session" , "true" , "false" , "false" , "default" , "2000" , "false" , "East US 2" , "2" , "100" , "200" , "30" , "false" , "false" , "10" , "QueryName" , "59409493805" , "Default" };
84+ private static final String CUSTOM_ITEM_SERIALIZER = "customItemSerializer" ;
85+ private static final String [] optionLabels = {E2E_TIMEOUT , CONSISTENCY_LEVEL , CONTENT_RESPONSE_ON_WRITE , NON_IDEMPOTENT_WRITE_RETRIES , BYPASS_CACHE , THROUGHPUT_CONTROL_GROUP_NAME , REQUEST_CHARGE_THRESHOLD , SCAN_IN_QUERY , EXCLUDE_REGIONS , MAX_DEGREE_OF_PARALLELISM , MAX_BUFFERED_ITEM_COUNT , RESPONSE_CONTINUATION_TOKEN_LIMIT_KB , MAX_ITEM_COUNT , QUERY_METRICS , INDEX_METRICS , MAX_PREFETCH_PAGE_COUNT , QUERY_NAME , KEYWORD_IDENTIFIERS , READ_CONSISTENCY_STRATEGY , CUSTOM_ITEM_SERIALIZER };
86+ private static final String [] initialOptions = {"20" , "Session" , "true" , "false" , "false" , "default" , "2000" , "false" , "East US 2" , "2" , "100" , "200" , "30" , "false" , "false" , "10" , "QueryName" , "59409493805" , "Default" , "initial" };
87+ private static final CosmosItemSerializer INITIAL_CUSTOM_ITEM_SERIALIZER = CosmosItemSerializer .DEFAULT_SERIALIZER ;
88+ private static final CosmosItemSerializer CHANGED_CUSTOM_ITEM_SERIALIZER = new DefaultCosmosItemSerializer (Utils .getSimpleObjectMapper ());
8489
8590 @ Factory (dataProvider = "clientBuildersWithApplyPolicies" )
8691 public OperationPoliciesTest (CosmosClientBuilder clientBuilder ) {
@@ -107,7 +112,8 @@ private static void createReadDeleteBatchEtcOptions(String operationType, String
107112 .setIntegratedCacheBypassed (Boolean .parseBoolean (prop .getProperty (BYPASS_CACHE ))))
108113 .setThroughputControlGroupName (prop .getProperty (THROUGHPUT_CONTROL_GROUP_NAME ))
109114 .setExcludeRegions (new ArrayList <>(Arrays .asList (prop .getProperty (EXCLUDE_REGIONS ).split ("," ))))
110- .setKeywordIdentifiers (new HashSet <>(Arrays .asList (prop .getProperty (KEYWORD_IDENTIFIERS ).split ("," ))));
115+ .setKeywordIdentifiers (new HashSet <>(Arrays .asList (prop .getProperty (KEYWORD_IDENTIFIERS ).split ("," ))))
116+ .setCustomItemSerializer (resolveCustomItemSerializer ());
111117 }
112118 }
113119
@@ -133,7 +139,8 @@ private static void createQueryReadAllItemsOptions(String operationType, String
133139 .setQueryName (prop .getProperty (QUERY_NAME ))
134140 .setConsistencyLevel (ConsistencyLevel .fromServiceSerializedFormat (prop .getProperty (CONSISTENCY_LEVEL )))
135141 .setReadConsistencyStrategy (ReadConsistencyStrategy .fromServiceSerializedFormat (prop .getProperty (READ_CONSISTENCY_STRATEGY )))
136- .setKeywordIdentifiers (new HashSet <>(Arrays .asList (prop .getProperty (KEYWORD_IDENTIFIERS ).split ("," ))));
142+ .setKeywordIdentifiers (new HashSet <>(Arrays .asList (prop .getProperty (KEYWORD_IDENTIFIERS ).split ("," ))))
143+ .setCustomItemSerializer (resolveCustomItemSerializer ());
137144 }
138145 }
139146
@@ -152,15 +159,17 @@ private static void createReadManyOptions(String spanName, CosmosRequestOptions
152159 .setIndexMetricsEnabled (Boolean .parseBoolean (prop .getProperty (INDEX_METRICS )))
153160 .setKeywordIdentifiers (new HashSet <>(Arrays .asList (prop .getProperty (KEYWORD_IDENTIFIERS ).split ("," ))))
154161 .setConsistencyLevel (ConsistencyLevel .fromServiceSerializedFormat (prop .getProperty (CONSISTENCY_LEVEL )))
155- .setReadConsistencyStrategy (ReadConsistencyStrategy .fromServiceSerializedFormat (prop .getProperty (READ_CONSISTENCY_STRATEGY )));
162+ .setReadConsistencyStrategy (ReadConsistencyStrategy .fromServiceSerializedFormat (prop .getProperty (READ_CONSISTENCY_STRATEGY )))
163+ .setCustomItemSerializer (resolveCustomItemSerializer ());
156164 }
157165 }
158166
159167 private static void createBulkOptions (String operationType , String spanName , CosmosRequestOptions cosmosRequestOptions ) {
160168 if (operationType .equals ("Batch" ) && spanName .contains ("nonTransactionalBatch" )) {
161169 cosmosRequestOptions .setExcludeRegions ((new ArrayList <>(Arrays .asList (prop .getProperty (EXCLUDE_REGIONS ).split ("," )))))
162170 .setThroughputControlGroupName (prop .getProperty (THROUGHPUT_CONTROL_GROUP_NAME ))
163- .setKeywordIdentifiers (new HashSet <>(Arrays .asList (prop .getProperty (KEYWORD_IDENTIFIERS ).split ("," ))));
171+ .setKeywordIdentifiers (new HashSet <>(Arrays .asList (prop .getProperty (KEYWORD_IDENTIFIERS ).split ("," ))))
172+ .setCustomItemSerializer (resolveCustomItemSerializer ());
164173 }
165174 }
166175
@@ -171,8 +180,25 @@ private static void createChangeFeedOptions(String spanName, CosmosRequestOption
171180 .setDiagnosticsThresholds (new CosmosDiagnosticsThresholds ().setRequestChargeThreshold (Float .parseFloat (prop .getProperty (REQUEST_CHARGE_THRESHOLD ))))
172181 .setMaxPrefetchPageCount (Integer .parseInt (prop .getProperty (MAX_PREFETCH_PAGE_COUNT )))
173182 .setMaxItemCount (Integer .parseInt (prop .getProperty (MAX_ITEM_COUNT )))
174- .setKeywordIdentifiers (new HashSet <>(Arrays .asList (prop .getProperty (KEYWORD_IDENTIFIERS ).split ("," ))));
183+ .setKeywordIdentifiers (new HashSet <>(Arrays .asList (prop .getProperty (KEYWORD_IDENTIFIERS ).split ("," ))))
184+ .setCustomItemSerializer (resolveCustomItemSerializer ());
185+ }
186+ }
187+
188+ private static CosmosItemSerializer resolveCustomItemSerializer () {
189+ String value = prop .getProperty (CUSTOM_ITEM_SERIALIZER );
190+ if ("changed" .equals (value )) {
191+ return CHANGED_CUSTOM_ITEM_SERIALIZER ;
192+ }
193+ return INITIAL_CUSTOM_ITEM_SERIALIZER ;
194+ }
195+
196+ private static CosmosItemSerializer resolveExpectedCustomItemSerializer (String [] options ) {
197+ String value = options [19 ];
198+ if ("changed" .equals (value )) {
199+ return CHANGED_CUSTOM_ITEM_SERIALIZER ;
175200 }
201+ return INITIAL_CUSTOM_ITEM_SERIALIZER ;
176202 }
177203
178204 @ DataProvider
@@ -242,8 +268,8 @@ public void afterMethod() {
242268 @ DataProvider (name = "changedOptions" )
243269 private String [][] createChangedOptions () {
244270 return new String [][] {
245- { "8" , "ConsistentPrefix" , "true" , "false" , "true" , "defaultChanged" , "1000" , "true" , "West US 2" , "4" , "200" , "400" , "100" , "false" , "true" , "20" , "QueryNameChanged" , "112" , "LatestCommitted" },
246- { "4" , "Eventual" , "false" , "true" , "true" , "defaultChanged" , "1000" , "true" , "West US 2" , "4" , "200" , "400" , "100" , "true" , "false" , "20" , "QueryNameChanged" , "221" , "LatestCommitted" },
271+ { "8" , "ConsistentPrefix" , "true" , "false" , "true" , "defaultChanged" , "1000" , "true" , "West US 2" , "4" , "200" , "400" , "100" , "false" , "true" , "20" , "QueryNameChanged" , "112" , "LatestCommitted" , "changed" },
272+ { "4" , "Eventual" , "false" , "true" , "true" , "defaultChanged" , "1000" , "true" , "West US 2" , "4" , "200" , "400" , "100" , "true" , "false" , "20" , "QueryNameChanged" , "221" , "LatestCommitted" , "changed" },
247273 initialOptions
248274 };
249275 }
@@ -699,6 +725,7 @@ private void validateOptions(String[] options, CosmosItemResponse<?> response, b
699725 assertThat (requestOptions .getDiagnosticsThresholds ().getRequestChargeThreshold ()).isEqualTo (Float .parseFloat (options [6 ]));
700726 assertThat (requestOptions .getExcludedRegions ()).isEqualTo (new ArrayList <>(Arrays .asList (options [8 ].split ("," ))));
701727 assertThat (requestOptions .getKeywordIdentifiers ()).isEqualTo (new HashSet <>(Arrays .asList (options [17 ].split ("," ))));
728+ assertThat (requestOptions .getCustomItemSerializer ()).isSameAs (resolveExpectedCustomItemSerializer (options ));
702729 }
703730
704731 private void validateOptions (String [] options , CosmosBatchResponse response ) {
@@ -708,6 +735,7 @@ private void validateOptions(String[] options, CosmosBatchResponse response) {
708735 assertThat (requestOptions .getDiagnosticsThresholds ().getRequestChargeThreshold ()).isEqualTo (Float .parseFloat (options [6 ]));
709736 assertThat (requestOptions .getExcludedRegions ()).isEqualTo (new ArrayList <>(Arrays .asList (options [8 ].split ("," ))));
710737 assertThat (requestOptions .getKeywordIdentifiers ()).isEqualTo (new HashSet <>(Arrays .asList (options [17 ].split ("," ))));
738+ assertThat (requestOptions .getCustomItemSerializer ()).isSameAs (resolveExpectedCustomItemSerializer (options ));
711739 }
712740
713741 private void validateOptions (String [] options , CosmosBulkItemResponse response ) {
@@ -716,6 +744,7 @@ private void validateOptions(String[] options, CosmosBulkItemResponse response)
716744 assertThat (requestOptions .getExcludedRegions ()).isEqualTo (new ArrayList <>(Arrays .asList (options [8 ].split ("," ))));
717745 assertThat (requestOptions .getThroughputControlGroupName ()).isEqualTo (options [5 ]);
718746 assertThat (requestOptions .getKeywordIdentifiers ()).isEqualTo (new HashSet <>(Arrays .asList (options [17 ].split ("," ))));
747+ assertThat (requestOptions .getCustomItemSerializer ()).isSameAs (resolveExpectedCustomItemSerializer (options ));
719748 }
720749
721750 private void validateOptions (String [] changedOptions , FeedResponse <InternalObjectNode > response , boolean isChangeFeed , boolean isReadMany ) {
@@ -757,6 +786,7 @@ private void validateOptions(String[] changedOptions, FeedResponse<InternalObjec
757786 assertThat (requestOptions .getQueryNameOrDefault ("" )).isEqualTo (changedOptions [16 ]);
758787 }
759788 assertThat (requestOptions .getKeywordIdentifiers ()).isEqualTo (new HashSet <>(Arrays .asList (changedOptions [17 ].split ("," ))));
789+ assertThat (requestOptions .getCustomItemSerializer ()).isSameAs (resolveExpectedCustomItemSerializer (changedOptions ));
760790 }
761791
762792 private void changeProperties (String [] values ) {
0 commit comments