Skip to content
Snippets Groups Projects
Commit 83e0f17b authored by piotr.kupczyk@id.ethz.ch's avatar piotr.kupczyk@id.ethz.ch
Browse files

SSDM-13578 : 2PT : Database and V3 Implementation - integration tests

parent 6f94f297
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
...@@ -336,6 +336,132 @@ public class Integration2PCTest extends AbstractIntegrationTest ...@@ -336,6 +336,132 @@ public class Integration2PCTest extends AbstractIntegrationTest
assertEquals(new String(bytesRead, StandardCharsets.UTF_8), CONTENT); assertEquals(new String(bytesRead, StandardCharsets.UTF_8), CONTENT);
} }
@Test
public void testPrepareFailsAtAS()
{
// make prepare fail at AS
setApplicationServerProxyInterceptor((method, defaultAction) ->
{
if (method != null && method.equals("prepareTransaction"))
{
throw new RuntimeException("Test prepare exception");
} else
{
defaultAction.call();
}
});
OpenBIS openBIS = createOpenBIS();
openBIS.setInteractiveSessionKey(TEST_INTERACTIVE_SESSION_KEY);
openBIS.login(USER, PASSWORD);
openBIS.beginTransaction();
String owner = OWNER_PREFIX + UUID.randomUUID();
String source = SOURCE_PREFIX + UUID.randomUUID();
byte[] bytesToWrite = CONTENT.getBytes(StandardCharsets.UTF_8);
openBIS.getAfsServerFacade().write(owner, source, 0L, bytesToWrite, calculateMD5(bytesToWrite));
assertTransactions(coordinatorApi.getTransactionMap(), new TestTransaction(openBIS.getTransactionId(), TransactionStatus.BEGIN_FINISHED));
SpaceCreation spaceCreation = new SpaceCreation();
spaceCreation.setCode(CODE_PREFIX + UUID.randomUUID());
SpacePermId spaceId = openBIS.createSpaces(List.of(spaceCreation)).get(0);
try
{
openBIS.commitTransaction();
fail();
} catch (Exception e)
{
assertEquals(e.getMessage(),
"Commit transaction '" + openBIS.getTransactionId() + "' failed.");
assertEquals(e.getCause().getMessage(),
"Prepare transaction '" + openBIS.getTransactionId()
+ "' failed for participant 'application-server'. The transaction was rolled back.");
}
assertTransactions(coordinatorApi.getTransactionMap());
// check data hasn't been committed
OpenBIS openBISNoTr = createOpenBIS();
openBISNoTr.login(USER, PASSWORD);
Space createdSpace = openBISNoTr.getSpaces(List.of(spaceId), new SpaceFetchOptions()).get(spaceId);
assertNull(createdSpace);
try
{
openBISNoTr.getAfsServerFacade().read(owner, source, 0L, bytesToWrite.length);
fail();
} catch (Exception expected)
{
}
}
@Test
public void testPrepareFailsAtAFS()
{
// make prepare fail at AFS
setAfsServerProxyInterceptor((method, defaultAction) ->
{
if (method != null && method.equals("prepare"))
{
throw new RuntimeException("Test prepare exception");
} else
{
defaultAction.call();
}
});
OpenBIS openBIS = createOpenBIS();
openBIS.setInteractiveSessionKey(TEST_INTERACTIVE_SESSION_KEY);
openBIS.login(USER, PASSWORD);
openBIS.beginTransaction();
String owner = OWNER_PREFIX + UUID.randomUUID();
String source = SOURCE_PREFIX + UUID.randomUUID();
byte[] bytesToWrite = CONTENT.getBytes(StandardCharsets.UTF_8);
openBIS.getAfsServerFacade().write(owner, source, 0L, bytesToWrite, calculateMD5(bytesToWrite));
assertTransactions(coordinatorApi.getTransactionMap(), new TestTransaction(openBIS.getTransactionId(), TransactionStatus.BEGIN_FINISHED));
SpaceCreation spaceCreation = new SpaceCreation();
spaceCreation.setCode(CODE_PREFIX + UUID.randomUUID());
SpacePermId spaceId = openBIS.createSpaces(List.of(spaceCreation)).get(0);
try
{
openBIS.commitTransaction();
fail();
} catch (Exception e)
{
assertEquals(e.getMessage(),
"Commit transaction '" + openBIS.getTransactionId() + "' failed.");
assertEquals(e.getCause().getMessage(),
"Prepare transaction '" + openBIS.getTransactionId()
+ "' failed for participant 'afs-server'. The transaction was rolled back.");
}
assertTransactions(coordinatorApi.getTransactionMap());
// check data hasn't been committed
OpenBIS openBISNoTr = createOpenBIS();
openBISNoTr.login(USER, PASSWORD);
Space createdSpace = openBISNoTr.getSpaces(List.of(spaceId), new SpaceFetchOptions()).get(spaceId);
assertNull(createdSpace);
try
{
openBISNoTr.getAfsServerFacade().read(owner, source, 0L, bytesToWrite.length);
fail();
} catch (Exception expected)
{
}
}
private void rollbackPreparedDatabaseTransactions() throws Exception private void rollbackPreparedDatabaseTransactions() throws Exception
{ {
try (Connection connection = applicationServerSpringContext.getBean(DataSource.class).getConnection(); try (Connection connection = applicationServerSpringContext.getBean(DataSource.class).getConnection();
......
...@@ -147,6 +147,8 @@ public abstract class AbstractIntegrationTest ...@@ -147,6 +147,8 @@ public abstract class AbstractIntegrationTest
public void beforeMethod(Method method) public void beforeMethod(Method method)
{ {
log("BEFORE " + method.getDeclaringClass().getName() + "." + method.getName()); log("BEFORE " + method.getDeclaringClass().getName() + "." + method.getName());
setApplicationServerProxyInterceptor(null);
setAfsServerProxyInterceptor(null);
} }
@AfterMethod @AfterMethod
...@@ -271,7 +273,17 @@ public abstract class AbstractIntegrationTest ...@@ -271,7 +273,17 @@ public abstract class AbstractIntegrationTest
+ Arrays.toString( + Arrays.toString(
remoteInvocation.getArguments())); remoteInvocation.getArguments()));
super.service(proxyRequest, response); if (applicationServerProxyInterceptor != null)
{
applicationServerProxyInterceptor.invoke(remoteInvocation.getMethodName(), () ->
{
super.service(proxyRequest, response);
return null;
});
} else
{
super.service(proxyRequest, response);
}
} catch (Exception e) } catch (Exception e)
{ {
System.out.println("[AS PROXY] failed"); System.out.println("[AS PROXY] failed");
...@@ -339,7 +351,7 @@ public abstract class AbstractIntegrationTest ...@@ -339,7 +351,7 @@ public abstract class AbstractIntegrationTest
if (afsServerProxyInterceptor != null) if (afsServerProxyInterceptor != null)
{ {
afsServerProxyInterceptor.invoke(parameters.get("method"), parameters, () -> afsServerProxyInterceptor.invoke(parameters.get("method"), () ->
{ {
super.service(proxyRequest, response); super.service(proxyRequest, response);
return null; return null;
...@@ -409,7 +421,7 @@ public abstract class AbstractIntegrationTest ...@@ -409,7 +421,7 @@ public abstract class AbstractIntegrationTest
public interface ProxyInterceptor public interface ProxyInterceptor
{ {
void invoke(String method, Map<String, String> parameters, Callable<Void> defaultAction) throws Exception; void invoke(String method, Callable<Void> defaultAction) throws Exception;
} }
private static class ProxyRequest extends HttpServletRequestWrapper private static class ProxyRequest extends HttpServletRequestWrapper
......
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