use of org.eclipse.dataspaceconnector.contract.negotiation.store.model.ContractNegotiationDocument in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosContractNegotiationStoreIntegrationTest method nextForState_verifySaveClearsLease.
@Test
void nextForState_verifySaveClearsLease() {
var n = generateNegotiation("test-id", ContractNegotiationStates.CONSUMER_OFFERED);
var doc = new ContractNegotiationDocument(n, partitionKey);
container.createItem(doc);
// verify nextForState sets the lease
var result = store.nextForState(ContractNegotiationStates.CONSUMER_OFFERED.code(), 5);
assertThat(result).hasSize(1).extracting(ContractNegotiation::getId).containsExactly(n.getId());
var storedDoc = readItem(n.getId());
assertThat(storedDoc.getLease()).isNotNull();
assertThat(storedDoc.getLease().getLeasedBy()).isEqualTo(CONNECTOR_ID);
assertThat(storedDoc.getLease().getLeasedAt()).isGreaterThan(0);
assertThat(storedDoc.getLease().getLeaseDuration()).isEqualTo(60000L);
n.transitionDeclining();
n.updateStateTimestamp();
store.save(n);
storedDoc = readItem(n.getId());
assertThat(storedDoc.getLease()).isNull();
assertThat(container.readAllItems(new PartitionKey(partitionKey), Object.class)).hasSize(1);
}
use of org.eclipse.dataspaceconnector.contract.negotiation.store.model.ContractNegotiationDocument in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosContractNegotiationStoreIntegrationTest method nextForState_verifyDelete.
@Test
@DisplayName("Verify that a leased entity can still be deleted")
void nextForState_verifyDelete() {
var n = generateNegotiation("test-id", ContractNegotiationStates.CONSUMER_OFFERED);
var doc = new ContractNegotiationDocument(n, partitionKey);
container.createItem(doc);
// verify nextForState sets the lease
var result = store.nextForState(ContractNegotiationStates.CONSUMER_OFFERED.code(), 5);
assertThat(result).hasSize(1).extracting(ContractNegotiation::getId).containsExactly(n.getId());
// verify entity can be deleted
store.delete(n.getId());
assertThat(container.readAllItems(new PartitionKey(partitionKey), Object.class)).isEmpty();
}
use of org.eclipse.dataspaceconnector.contract.negotiation.store.model.ContractNegotiationDocument in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosContractNegotiationStore method save.
@Override
public void save(ContractNegotiation negotiation) {
try {
leaseContext.acquireLease(negotiation.getId());
with(retryPolicy).run(() -> cosmosDbApi.saveItem(new ContractNegotiationDocument(negotiation, partitionKey)));
leaseContext.breakLease(negotiation.getId());
} catch (BadRequestException ex) {
throw new EdcException(ex);
}
}
use of org.eclipse.dataspaceconnector.contract.negotiation.store.model.ContractNegotiationDocument in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosContractNegotiationStoreIntegrationTest method nextForState_noResult.
@Test
void nextForState_noResult() {
var state = ContractNegotiationStates.CONFIRMED;
var n = generateNegotiation(state);
container.createItem(new ContractNegotiationDocument(n, partitionKey));
var result = store.nextForState(ContractNegotiationStates.PROVIDER_OFFERING.code(), 10);
assertThat(result).isNotNull().isEmpty();
}
use of org.eclipse.dataspaceconnector.contract.negotiation.store.model.ContractNegotiationDocument in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosContractNegotiationStoreIntegrationTest method nextForState_exceedsLimit.
@Test
void nextForState_exceedsLimit() {
var state = ContractNegotiationStates.CONFIRMED;
var numElements = 10;
var preparedNegotiations = IntStream.range(0, numElements).mapToObj(i -> generateNegotiation(state)).peek(n -> container.createItem(new ContractNegotiationDocument(n, partitionKey))).collect(Collectors.toList());
var result = store.nextForState(state.code(), 4);
assertThat(result).hasSize(4).allSatisfy(r -> assertThat(preparedNegotiations).extracting(ContractNegotiation::getId).contains(r.getId()));
}
Aggregations