use of org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosTransferProcessStoreIntegrationTest method invokeStoreProcedure.
@Test
void invokeStoreProcedure() {
// create one item
var tp = createTransferProcess("proc1");
store.create(tp);
List<Object> procedureParams = Arrays.asList(100, 5, connectorId);
CosmosStoredProcedureRequestOptions options = new CosmosStoredProcedureRequestOptions();
options.setPartitionKey(PartitionKey.NONE);
CosmosStoredProcedureResponse sprocResponse = container.getScripts().getStoredProcedure("nextForState").execute(procedureParams, options);
var result = sprocResponse.getResponseAsString();
var l = typeManager.readValue(result, List.class);
List<TransferProcessDocument> documents = (List<TransferProcessDocument>) l.stream().map(o -> typeManager.writeValueAsString(o)).map(json -> typeManager.readValue(json.toString(), TransferProcessDocument.class)).collect(Collectors.toList());
assertThat(documents).allSatisfy(document -> {
assertThat(document.getLease()).isNotNull().hasFieldOrPropertyWithValue("leasedBy", connectorId).hasFieldOrProperty("leasedAt");
});
}
use of org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosTransferProcessStore method update.
@Override
public void update(TransferProcess process) {
var document = new TransferProcessDocument(process, partitionKey);
try {
leaseContext.acquireLease(process.getId());
failsafeExecutor.run(() -> cosmosDbApi.saveItem(document));
leaseContext.breakLease(process.getId());
} catch (BadRequestException ex) {
throw new EdcException(ex);
}
}
use of org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosTransferProcessStoreIntegrationTest method nextForState_verifyDelete.
@Test
@DisplayName("Verify that a leased entity can still be deleted")
void nextForState_verifyDelete() {
var tp = createTransferProcess("test-id", TransferProcessStates.IN_PROGRESS);
var doc = new TransferProcessDocument(tp, partitionKey);
container.upsertItem(doc);
var result = store.nextForState(TransferProcessStates.IN_PROGRESS.code(), 5);
assertThat(result).hasSize(1);
// make sure the lease is acquired
var leasedDoc = readDocument(tp.getId());
assertThat(leasedDoc.getLease()).isNotNull();
store.delete(tp.getId());
assertThat(container.readAllItems(new PartitionKey(partitionKey), Object.class)).isEmpty();
}
use of org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosTransferProcessStoreIntegrationTest method nextForState_shouldOnlyReturnFreeItems.
@Test
void nextForState_shouldOnlyReturnFreeItems() {
String id1 = "process1";
var tp = createTransferProcess(id1, TransferProcessStates.INITIAL);
String id2 = "process2";
var tp2 = createTransferProcess(id2, TransferProcessStates.INITIAL);
store.create(tp);
store.create(tp2);
TransferProcessDocument item = readDocument(id2);
item.acquireLease("test-leaser");
container.upsertItem(item);
// act - one should be ignored
List<TransferProcess> processes = store.nextForState(TransferProcessStates.INITIAL.code(), 5);
assertThat(processes).hasSize(1).allMatch(p -> p.getId().equals(id1));
}
use of org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosTransferProcessStoreIntegrationTest method invokeStoredProcedure.
@Test
void invokeStoredProcedure() {
// create one item
var tp = createTransferProcess("proc1");
store.create(tp);
List<Object> procedureParams = Arrays.asList(100, 5, connectorId);
CosmosStoredProcedureRequestOptions options = new CosmosStoredProcedureRequestOptions();
options.setPartitionKey(PartitionKey.NONE);
CosmosStoredProcedureResponse sprocResponse = container.getScripts().getStoredProcedure("nextForState").execute(procedureParams, options);
var result = sprocResponse.getResponseAsString();
var l = typeManager.readValue(result, List.class);
List<TransferProcessDocument> documents = (List<TransferProcessDocument>) l.stream().map(o -> typeManager.writeValueAsString(o)).map(json -> typeManager.readValue(json.toString(), TransferProcessDocument.class)).collect(Collectors.toList());
assertThat(documents).allSatisfy(document -> {
assertThat(document.getLease()).isNotNull().hasFieldOrPropertyWithValue("leasedBy", connectorId).hasFieldOrProperty("leasedAt");
});
}
Aggregations