@@ -89,6 +89,7 @@ public class SnapshotTest {
89
89
.addColumn (ANY_NAME_4 , DataType .TEXT )
90
90
.addPartitionKey (ANY_NAME_1 )
91
91
.addClusteringKey (ANY_NAME_2 )
92
+ .addSecondaryIndex (ANY_NAME_4 )
92
93
.build ());
93
94
94
95
private Snapshot snapshot ;
@@ -186,6 +187,15 @@ private Get prepareAnotherGet() {
186
187
.forTable (ANY_TABLE_NAME );
187
188
}
188
189
190
+ private Get prepareGetWithIndex () {
191
+ Key indexKey = new Key (ANY_NAME_4 , ANY_TEXT_1 );
192
+ return Get .newBuilder ()
193
+ .namespace (ANY_NAMESPACE_NAME )
194
+ .table (ANY_TABLE_NAME )
195
+ .indexKey (indexKey )
196
+ .build ();
197
+ }
198
+
189
199
private Scan prepareScan () {
190
200
Key partitionKey = new Key (ANY_NAME_1 , ANY_TEXT_1 );
191
201
Key clusteringKey = new Key (ANY_NAME_2 , ANY_TEXT_2 );
@@ -206,6 +216,15 @@ private Scan prepareScanWithLimit(int limit) {
206
216
.build ();
207
217
}
208
218
219
+ private Scan prepareScanWithIndex () {
220
+ Key indexKey = new Key (ANY_NAME_4 , ANY_TEXT_1 );
221
+ return Scan .newBuilder ()
222
+ .namespace (ANY_NAMESPACE_NAME )
223
+ .table (ANY_TABLE_NAME )
224
+ .indexKey (indexKey )
225
+ .build ();
226
+ }
227
+
209
228
private Scan prepareCrossPartitionScan () {
210
229
return prepareCrossPartitionScan (ANY_NAMESPACE_NAME , ANY_TABLE_NAME );
211
230
}
@@ -1010,6 +1029,83 @@ public void toSerializable_ReadSetExtended_ShouldThrowValidationConflictExceptio
1010
1029
verify (storage ).get (getWithProjections );
1011
1030
}
1012
1031
1032
+ @ Test
1033
+ public void toSerializable_GetSetWithGetWithIndex_ShouldProcessWithoutExceptions ()
1034
+ throws ExecutionException {
1035
+ // Arrange
1036
+ snapshot = prepareSnapshot (Isolation .SERIALIZABLE );
1037
+ Get getWithIndex = prepareGetWithIndex ();
1038
+ TransactionResult txResult = prepareResult (ANY_ID + "x" );
1039
+ snapshot .putIntoGetSet (getWithIndex , Optional .of (txResult ));
1040
+ DistributedStorage storage = mock (DistributedStorage .class );
1041
+ Scan scanWithIndex =
1042
+ prepareScanWithIndex ().withProjections (Arrays .asList (Attribute .ID , ANY_NAME_1 , ANY_NAME_2 ));
1043
+ Scanner scanner = mock (Scanner .class );
1044
+ when (scanner .one ()).thenReturn (Optional .of (txResult )).thenReturn (Optional .empty ());
1045
+ when (storage .scan (scanWithIndex )).thenReturn (scanner );
1046
+
1047
+ // Act Assert
1048
+ assertThatCode (() -> snapshot .toSerializable (storage )).doesNotThrowAnyException ();
1049
+
1050
+ // Assert
1051
+ verify (storage ).scan (scanWithIndex );
1052
+ }
1053
+
1054
+ @ Test
1055
+ public void
1056
+ toSerializable_GetSetWithGetWithIndex_RecordInserted_ShouldThrowValidationConflictException ()
1057
+ throws ExecutionException {
1058
+ // Arrange
1059
+ snapshot = prepareSnapshot (Isolation .SERIALIZABLE );
1060
+ Get getWithIndex = prepareGetWithIndex ();
1061
+ TransactionResult result1 = prepareResult (ANY_ID + "x" , ANY_TEXT_1 , ANY_TEXT_2 );
1062
+ TransactionResult result2 = prepareResult (ANY_ID + "xx" , ANY_TEXT_1 , ANY_TEXT_3 );
1063
+ snapshot .putIntoGetSet (getWithIndex , Optional .of (result1 ));
1064
+ DistributedStorage storage = mock (DistributedStorage .class );
1065
+ Scan scanWithIndex =
1066
+ prepareScanWithIndex ().withProjections (Arrays .asList (Attribute .ID , ANY_NAME_1 , ANY_NAME_2 ));
1067
+ Scanner scanner = mock (Scanner .class );
1068
+ when (scanner .one ())
1069
+ .thenReturn (Optional .of (result1 ))
1070
+ .thenReturn (Optional .of (result2 ))
1071
+ .thenReturn (Optional .empty ());
1072
+ when (storage .scan (scanWithIndex )).thenReturn (scanner );
1073
+
1074
+ // Act Assert
1075
+ assertThatThrownBy (() -> snapshot .toSerializable (storage ))
1076
+ .isInstanceOf (ValidationConflictException .class );
1077
+
1078
+ // Assert
1079
+ verify (storage ).scan (scanWithIndex );
1080
+ }
1081
+
1082
+ @ Test
1083
+ public void
1084
+ toSerializable_GetSetWithGetWithIndex_RecordInsertedByMySelf_ShouldProcessWithoutExceptions ()
1085
+ throws ExecutionException {
1086
+ // Arrange
1087
+ snapshot = prepareSnapshot (Isolation .SERIALIZABLE );
1088
+ Get getWithIndex = prepareGetWithIndex ();
1089
+ TransactionResult result1 = prepareResult (ANY_ID + "x" , ANY_TEXT_1 , ANY_TEXT_2 );
1090
+ TransactionResult result2 = prepareResult (ANY_ID , ANY_TEXT_1 , ANY_TEXT_3 );
1091
+ snapshot .putIntoGetSet (getWithIndex , Optional .of (result1 ));
1092
+ DistributedStorage storage = mock (DistributedStorage .class );
1093
+ Scan scanWithIndex =
1094
+ prepareScanWithIndex ().withProjections (Arrays .asList (Attribute .ID , ANY_NAME_1 , ANY_NAME_2 ));
1095
+ Scanner scanner = mock (Scanner .class );
1096
+ when (scanner .one ())
1097
+ .thenReturn (Optional .of (result1 ))
1098
+ .thenReturn (Optional .of (result2 ))
1099
+ .thenReturn (Optional .empty ());
1100
+ when (storage .scan (scanWithIndex )).thenReturn (scanner );
1101
+
1102
+ // Act Assert
1103
+ assertThatCode (() -> snapshot .toSerializable (storage )).doesNotThrowAnyException ();
1104
+
1105
+ // Assert
1106
+ verify (storage ).scan (scanWithIndex );
1107
+ }
1108
+
1013
1109
@ Test
1014
1110
public void toSerializable_ScanSetNotChanged_ShouldProcessWithoutExceptions ()
1015
1111
throws ExecutionException {
0 commit comments