@@ -941,6 +941,57 @@ public void coordinatorNamespaceShouldHandleCorrectly() throws ExecutionExceptio
941941 .isInstanceOf (IllegalArgumentException .class );
942942 }
943943
944+ @ Test
945+ public void
946+ createTable_WithTransactionMetadataDecouplingEnabledAndDataTableAlreadyExists_ShouldThrowIllegalArgumentException ()
947+ throws ExecutionException {
948+ // Arrange
949+ TableMetadata tableMetadata =
950+ TableMetadata .newBuilder ()
951+ .addColumn ("col1" , DataType .INT )
952+ .addColumn ("col2" , DataType .INT )
953+ .addPartitionKey ("col1" )
954+ .build ();
955+
956+ Map <String , String > options =
957+ ImmutableMap .of (ConsensusCommitAdmin .TRANSACTION_METADATA_DECOUPLING , "true" );
958+
959+ StorageInfo storageInfo =
960+ new StorageInfoImpl ("jdbc" , MutationAtomicityUnit .STORAGE , Integer .MAX_VALUE , true );
961+ when (distributedStorageAdmin .getStorageInfo (NAMESPACE )).thenReturn (storageInfo );
962+ when (distributedStorageAdmin .tableExists (NAMESPACE , TABLE + "_data" )).thenReturn (true );
963+
964+ // Act Assert
965+ assertThatThrownBy (() -> admin .createTable (NAMESPACE , TABLE , tableMetadata , options ))
966+ .isInstanceOf (IllegalArgumentException .class );
967+ }
968+
969+ @ Test
970+ public void
971+ createTable_WithTransactionMetadataDecouplingEnabledAndMetadataTableAlreadyExists_ShouldThrowIllegalArgumentException ()
972+ throws ExecutionException {
973+ // Arrange
974+ TableMetadata tableMetadata =
975+ TableMetadata .newBuilder ()
976+ .addColumn ("col1" , DataType .INT )
977+ .addColumn ("col2" , DataType .INT )
978+ .addPartitionKey ("col1" )
979+ .build ();
980+
981+ Map <String , String > options =
982+ ImmutableMap .of (ConsensusCommitAdmin .TRANSACTION_METADATA_DECOUPLING , "true" );
983+
984+ StorageInfo storageInfo =
985+ new StorageInfoImpl ("jdbc" , MutationAtomicityUnit .STORAGE , Integer .MAX_VALUE , true );
986+ when (distributedStorageAdmin .getStorageInfo (NAMESPACE )).thenReturn (storageInfo );
987+ when (distributedStorageAdmin .tableExists (NAMESPACE , TABLE + "_data" )).thenReturn (false );
988+ when (distributedStorageAdmin .tableExists (NAMESPACE , TABLE + "_tx_metadata" )).thenReturn (true );
989+
990+ // Act Assert
991+ assertThatThrownBy (() -> admin .createTable (NAMESPACE , TABLE , tableMetadata , options ))
992+ .isInstanceOf (IllegalArgumentException .class );
993+ }
994+
944995 @ Test
945996 public void dropTable_ForVirtualTable_ShouldDropVirtualTableAndSourceTables ()
946997 throws ExecutionException {
@@ -1138,4 +1189,43 @@ public VirtualTableJoinType getJoinType() {
11381189 assertThatThrownBy (() -> admin .importTable (NAMESPACE , TABLE , options , overrideColumnsType ))
11391190 .isInstanceOf (IllegalArgumentException .class );
11401191 }
1192+
1193+ @ Test
1194+ public void
1195+ importTable_WithTransactionMetadataDecouplingEnabledAndMetadataTableAlreadyExists_ShouldThrowIllegalArgumentException ()
1196+ throws ExecutionException {
1197+ // Arrange
1198+ Map <String , String > options =
1199+ ImmutableMap .of (ConsensusCommitAdmin .TRANSACTION_METADATA_DECOUPLING , "true" );
1200+ Map <String , DataType > overrideColumnsType = Collections .emptyMap ();
1201+
1202+ StorageInfo storageInfo =
1203+ new StorageInfoImpl ("jdbc" , MutationAtomicityUnit .STORAGE , Integer .MAX_VALUE , true );
1204+ when (distributedStorageAdmin .getStorageInfo (NAMESPACE )).thenReturn (storageInfo );
1205+ when (distributedStorageAdmin .tableExists (NAMESPACE , TABLE + "_tx_metadata" )).thenReturn (true );
1206+
1207+ // Act Assert
1208+ assertThatThrownBy (() -> admin .importTable (NAMESPACE , TABLE , options , overrideColumnsType ))
1209+ .isInstanceOf (IllegalArgumentException .class );
1210+ }
1211+
1212+ @ Test
1213+ public void
1214+ importTable_WithTransactionMetadataDecouplingEnabledAndImportedTableAlreadyExists_ShouldThrowIllegalArgumentException ()
1215+ throws ExecutionException {
1216+ // Arrange
1217+ Map <String , String > options =
1218+ ImmutableMap .of (ConsensusCommitAdmin .TRANSACTION_METADATA_DECOUPLING , "true" );
1219+ Map <String , DataType > overrideColumnsType = Collections .emptyMap ();
1220+
1221+ StorageInfo storageInfo =
1222+ new StorageInfoImpl ("jdbc" , MutationAtomicityUnit .STORAGE , Integer .MAX_VALUE , true );
1223+ when (distributedStorageAdmin .getStorageInfo (NAMESPACE )).thenReturn (storageInfo );
1224+ when (distributedStorageAdmin .tableExists (NAMESPACE , TABLE + "_tx_metadata" )).thenReturn (false );
1225+ when (distributedStorageAdmin .tableExists (NAMESPACE , TABLE + "_scalardb" )).thenReturn (true );
1226+
1227+ // Act Assert
1228+ assertThatThrownBy (() -> admin .importTable (NAMESPACE , TABLE , options , overrideColumnsType ))
1229+ .isInstanceOf (IllegalArgumentException .class );
1230+ }
11411231}
0 commit comments