Skip to content

Commit fef6199

Browse files
committed
apply suggestions
1 parent cb6adbb commit fef6199

File tree

3 files changed

+18
-38
lines changed

3 files changed

+18
-38
lines changed

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataimport/ImportCommand.java

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.scalar.db.api.DistributedTransaction;
88
import com.scalar.db.api.DistributedTransactionAdmin;
99
import com.scalar.db.api.TableMetadata;
10-
import com.scalar.db.common.CoreError;
1110
import com.scalar.db.dataloader.core.DataLoaderError;
1211
import com.scalar.db.dataloader.core.FileFormat;
1312
import com.scalar.db.dataloader.core.ScalarDbMode;
@@ -272,32 +271,22 @@ void validateTransactionMode(TransactionFactory transactionFactory) {
272271
// Try to start a read only transaction to verify the transaction manager is properly
273272
// configured
274273
transaction = transactionFactory.getTransactionManager().startReadOnly();
275-
} catch (Exception e) {
276-
// Check for specific error about beginning transaction not allowed
277-
if (e.getMessage() != null
278-
&& e.getMessage()
279-
.contains(
280-
CoreError.SINGLE_CRUD_OPERATION_TRANSACTION_BEGINNING_TRANSACTION_NOT_ALLOWED
281-
.buildCode())) {
282-
throw new ParameterException(
283-
spec.commandLine(),
284-
DataLoaderError.INVALID_TRANSACTION_MODE.buildMessage(
285-
"The current configuration does not support TRANSACTION mode. "
286-
+ "Please try with STORAGE mode or check your ScalarDB configuration. "
287-
+ "Error: "
288-
+ e.getClass().getSimpleName()
289-
+ " - "
290-
+ e.getMessage()));
291-
}
292-
293-
// Other exceptions - configuration or runtime error
274+
} catch (UnsupportedOperationException e) {
275+
// Transaction mode is not supported by the configured transaction manager
294276
throw new ParameterException(
295277
spec.commandLine(),
296278
DataLoaderError.INVALID_TRANSACTION_MODE.buildMessage(
297-
"Failed to validate transaction mode compatibility. Error: "
279+
"Please try with STORAGE mode or check your ScalarDB configuration. "
280+
+ "Error: "
298281
+ e.getClass().getSimpleName()
299282
+ " - "
300283
+ e.getMessage()));
284+
} catch (Exception e) {
285+
// Other exceptions - configuration or runtime error
286+
throw new ParameterException(
287+
spec.commandLine(),
288+
DataLoaderError.TRANSACTION_MODE_VALIDATION_FAILED.buildMessage(
289+
"Error: " + e.getClass().getSimpleName() + " - " + e.getMessage()));
301290
} finally {
302291
// Ensure transaction is aborted
303292
if (transaction != null) {

data-loader/cli/src/test/java/com/scalar/db/dataloader/cli/command/dataimport/ImportCommandTest.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
import static org.mockito.Mockito.when;
88

99
import com.scalar.db.api.DistributedTransactionManager;
10-
import com.scalar.db.common.CoreError;
1110
import com.scalar.db.dataloader.core.FileFormat;
1211
import com.scalar.db.dataloader.core.ScalarDbMode;
1312
import com.scalar.db.dataloader.core.dataimport.ImportMode;
14-
import com.scalar.db.exception.transaction.TransactionException;
1513
import com.scalar.db.service.TransactionFactory;
1614
import java.io.IOException;
1715
import java.nio.file.Files;
@@ -288,18 +286,14 @@ void call_withoutMaxThreads_shouldDefaultToAvailableProcessors() {
288286
}
289287

290288
@Test
291-
void validateTransactionMode_withInvalidConfig_shouldThrowException() throws Exception {
292-
// Arrange - Mock TransactionFactory to throw exception with error
289+
void validateTransactionMode_withUnsupportedOperation_shouldThrowException() throws Exception {
290+
// Arrange - Mock TransactionFactory to throw UnsupportedOperationException
293291
TransactionFactory mockFactory = mock(TransactionFactory.class);
294292
DistributedTransactionManager mockManager = mock(DistributedTransactionManager.class);
295293

296294
when(mockFactory.getTransactionManager()).thenReturn(mockManager);
297295
when(mockManager.startReadOnly())
298-
.thenThrow(
299-
new TransactionException(
300-
CoreError.SINGLE_CRUD_OPERATION_TRANSACTION_BEGINNING_TRANSACTION_NOT_ALLOWED
301-
.buildMessage(),
302-
null));
296+
.thenThrow(new UnsupportedOperationException("Transaction mode is not supported"));
303297

304298
ImportCommand command = new ImportCommand();
305299
CommandLine cmd = new CommandLine(command);
@@ -312,13 +306,8 @@ void validateTransactionMode_withInvalidConfig_shouldThrowException() throws Exc
312306
CommandLine.ParameterException.class,
313307
() -> command.validateTransactionMode(mockFactory));
314308

315-
assertTrue(thrown.getMessage().contains("does not support TRANSACTION mode"));
316-
assertTrue(
317-
thrown
318-
.getMessage()
319-
.contains(
320-
CoreError.SINGLE_CRUD_OPERATION_TRANSACTION_BEGINNING_TRANSACTION_NOT_ALLOWED
321-
.buildCode()));
309+
assertTrue(thrown.getMessage().contains("TRANSACTION mode is not compatible"));
310+
assertTrue(thrown.getMessage().contains("UnsupportedOperationException"));
322311
}
323312

324313
@Test
@@ -341,7 +330,7 @@ void validateTransactionMode_withOtherException_shouldThrowException() throws Ex
341330
CommandLine.ParameterException.class,
342331
() -> command.validateTransactionMode(mockFactory));
343332

344-
assertTrue(thrown.getMessage().contains("Failed to validate transaction mode"));
333+
assertTrue(thrown.getMessage().contains("Failed to validate TRANSACTION mode"));
345334
assertTrue(thrown.getMessage().contains("RuntimeException"));
346335
assertTrue(thrown.getMessage().contains("Connection failed"));
347336
}

data-loader/core/src/main/java/com/scalar/db/dataloader/core/DataLoaderError.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ public enum DataLoaderError implements ScalarDbError {
222222
"TRANSACTION mode is not compatible with the current configuration. %s",
223223
"",
224224
""),
225+
TRANSACTION_MODE_VALIDATION_FAILED(
226+
Category.USER_ERROR, "0059", "Failed to validate TRANSACTION mode. %s", "", ""),
225227

226228
//
227229
// Errors for the internal error category

0 commit comments

Comments
 (0)