Skip to content
Snippets Groups Projects
Commit a16b76d7 authored by jakubs's avatar jakubs
Browse files

SP-45, BIS-21 add new hook for transaction rollback in jython v2 dropboxes

SVN: 25263
parent 0d2e88d8
No related branches found
No related tags found
No related merge requests found
......@@ -79,6 +79,11 @@ public class JythonTopLevelDataSetHandler<T extends DataSetInformation> extends
*/
POST_REGISTRATION_FUNCTION_NAME("post_metadata_registration", 1),
/**
* The name of the function to define to hook into the transaction rollback mechanism.
*/
ROLLBACK_PRE_REGISTRATION_FUNCTION_NAME("rollback_pre_registration", 2),
/**
* The name of the function called when secondary transactions, DynamicTransactionQuery
* objects, fail.
......@@ -313,22 +318,35 @@ public class JythonTopLevelDataSetHandler<T extends DataSetInformation> extends
DataSetStorageAlgorithmRunner<T> algorithmRunner, Throwable ex)
{
PythonInterpreter interpreter = getInterpreterFromService(service);
PyFunction function =
tryJythonFunction(interpreter,
JythonHookFunction.ROLLBACK_TRANSACTION_FUNCTION_NAME);
JythonHookFunction.ROLLBACK_PRE_REGISTRATION_FUNCTION_NAME);
if (null != function)
{
invokeRollbackTransactionFunction(function, service, transaction, algorithmRunner, ex);
invokeTransactionFunctionWithContext(function, service, transaction, ex);
} else if (shouldUseOldJythonHookFunctions())
{
// No Rollback transaction function was called, see if the rollback service function was
// defined, and call it.
function =
tryJythonFunction(interpreter,
JythonHookFunction.ROLLBACK_SERVICE_FUNCTION_NAME);
JythonHookFunction.ROLLBACK_TRANSACTION_FUNCTION_NAME);
if (null != function)
{
invokeRollbackServiceFunction(function, service, ex);
invokeRollbackTransactionFunction(function, service, transaction, algorithmRunner,
ex);
} else
{
// No Rollback transaction function was called, see if the rollback service function
// was
// defined, and call it.
function =
tryJythonFunction(interpreter,
JythonHookFunction.ROLLBACK_SERVICE_FUNCTION_NAME);
if (null != function)
{
invokeRollbackServiceFunction(function, service, ex);
}
}
}
}
......@@ -432,9 +450,17 @@ public class JythonTopLevelDataSetHandler<T extends DataSetInformation> extends
}
private void invokeTransactionFunctionWithContext(PyFunction function,
DataSetRegistrationService<T> service, DataSetRegistrationTransaction<T> transaction)
DataSetRegistrationService<T> service, DataSetRegistrationTransaction<T> transaction,
Object... additionalArgs)
{
invokeFuncion(service, function, transaction.getTransactionPersistentMap());
if (additionalArgs.length > 0)
{
invokeFuncion(service, function, transaction.getTransactionPersistentMap(),
additionalArgs);
} else
{
invokeFuncion(service, function, transaction.getTransactionPersistentMap());
}
}
private void invokeDidEncounterSecondaryTransactionErrorsFunction(PyFunction function,
......
......@@ -643,9 +643,10 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractJythonDataSetH
Throwable t = isErrorCausedByUnexpectedInvocation(exception);
if (t != null)
{
throw new RuntimeException("Extracted unexpected invocation error "+t.getMessage(), t);
throw new RuntimeException("Extracted unexpected invocation error "
+ t.getMessage(), t);
}
if (testCase.exceptionAcceptor != null)
{
assertTrue("Exception " + exception + "was not accepted by validator",
......@@ -797,6 +798,7 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractJythonDataSetH
} else if (testCase.failurePoint
.compareTo(TestCaseParameters.FailurePoint.DURING_VALIDATION) <= 0)
{
assertFalse(handler.getExpectations().didPreRegistrationRollbackHappen);
assertFalse(handler.getExpectations().didRollbackServiceFunctionRun);
assertFalse(handler.getExpectations().didTransactionRollbackHappen);
assertFalse(handler.getExpectations().didRollbackTransactionFunctionRunHappen);
......@@ -809,8 +811,9 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractJythonDataSetH
} else
{
assertFalse(handler.getExpectations().didRollbackServiceFunctionRun);
assertTrue(handler.getExpectations().didPreRegistrationRollbackHappen);
assertFalse(handler.getExpectations().didRollbackTransactionFunctionRunHappen);
assertTrue(handler.getExpectations().didTransactionRollbackHappen);
assertTrue(handler.getExpectations().didRollbackTransactionFunctionRunHappen);
assertTrue(handler.getExpectations().didPreRegistrationFunctionRunHappen);
assertFalse(handler.getExpectations().didPostRegistrationFunctionRunHappen);
......
......@@ -36,10 +36,11 @@ public class TestingDataSetHandlerExpectations
protected boolean didServiceRollbackHappen = false;
protected boolean didPreRegistrationRollbackHappen = false;
protected String registrationContextError;
public boolean isShouldRegistrationFail()
{
return shouldRegistrationFail;
......@@ -88,6 +89,9 @@ public class TestingDataSetHandlerExpectations
readBoolean(interpreter, "didPostStorageFunctionRunHappen");
didSecondaryTransactionErrorNotificationHappen =
readBoolean(interpreter, "didSecondaryTransactionErrorNotificationHappen");
didPreRegistrationRollbackHappen =
readBoolean(interpreter, "didPreRegistrationRollbackHappen");
registrationContextError = interpreter.get("contextTestFailed", String.class);
}
......
......@@ -2,6 +2,10 @@ def rollback_transaction(service, transaction, algorithmRunner, throwable):
global didTransactionRollbackHappen
didTransactionRollbackHappen = True
def rollback_pre_registration(context, throwable):
global didPreRegistrationRollbackHappen
didPreRegistrationRollbackHappen = True
def commit_transaction(service, transaction):
global didTransactionCommitHappen
didTransactionCommitHappen = True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment