Skip to content
Snippets Groups Projects
Commit 979f2467 authored by Adam Laskowski's avatar Adam Laskowski
Browse files

SSDM-13251: Added simple implementations of TwoPhaseTransactionAPI methods to...

SSDM-13251: Added simple implementations of TwoPhaseTransactionAPI methods to server-data-store java client
parent 1bb99df8
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
......@@ -187,31 +187,39 @@ public final class AfsClient implements PublicAPI
@Override
public void begin(final UUID transactionId) throws Exception
{
validateSessionToken();
Map<String, Object> parameters =
Map.of("transactionId", transactionId,
"sessionToken", getSessionToken());
request("POST", "begin", Map.of(), jsonObjectMapper.writeValue(parameters));
}
@Override
public Boolean prepare() throws Exception
{
return null;
validateSessionToken();
return request("POST", "prepare", Map.of());
}
@Override
public void commit() throws Exception
{
validateSessionToken();
request("POST", "commit", Map.of());
}
@Override
public void rollback() throws Exception
{
validateSessionToken();
request("POST", "rollback", Map.of());
}
@Override
public List<UUID> recover() throws Exception
{
return null;
validateSessionToken();
return request("POST", "recover", Map.of());
}
private <T> T request(@NonNull final String httpMethod, @NonNull final String apiMethod,
......
......@@ -5,6 +5,8 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
import java.net.URI;
import java.util.List;
import java.util.UUID;
import org.junit.*;
......@@ -179,28 +181,61 @@ public class AfsClientTest
}
@Test
public void testBegin()
public void begin_methodIsPost() throws Exception
{
login();
UUID transactionId = UUID.randomUUID();
httpServer.setNextResponse("{\"result\": null}");
afsClient.begin(transactionId);
assertEquals("POST", httpServer.getHttpExchange().getRequestMethod());
}
@Test
public void testPrepare()
public void prepare_methodIsPost() throws Exception
{
login();
httpServer.setNextResponse("{\"result\": true}");
Boolean result = afsClient.prepare();
assertEquals("POST", httpServer.getHttpExchange().getRequestMethod());
assertTrue(result);
}
@Test
public void testCommit()
public void commit_methodIsPost() throws Exception
{
login();
httpServer.setNextResponse("{\"result\": null}");
afsClient.commit();
assertEquals("POST", httpServer.getHttpExchange().getRequestMethod());
}
@Test
public void testRollback()
public void rollback_methodIsPost() throws Exception
{
login();
httpServer.setNextResponse("{\"result\": null}");
afsClient.rollback();
assertEquals("POST", httpServer.getHttpExchange().getRequestMethod());
}
@Test
public void testRecover()
public void recover_methodIsPost() throws Exception
{
login();
httpServer.setNextResponse("{\"result\": null}");
List<UUID> result = afsClient.recover();
assertEquals("POST", httpServer.getHttpExchange().getRequestMethod());
assertNull(result);
}
private void login() throws Exception
......
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