Search in sources :

Example 1 with ContractNegotiationDocument

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);
}
Also used : ContractNegotiationDocument(org.eclipse.dataspaceconnector.contract.negotiation.store.model.ContractNegotiationDocument) PartitionKey(com.azure.cosmos.models.PartitionKey) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with ContractNegotiationDocument

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();
}
Also used : ContractNegotiationDocument(org.eclipse.dataspaceconnector.contract.negotiation.store.model.ContractNegotiationDocument) PartitionKey(com.azure.cosmos.models.PartitionKey) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with ContractNegotiationDocument

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);
    }
}
Also used : ContractNegotiationDocument(org.eclipse.dataspaceconnector.contract.negotiation.store.model.ContractNegotiationDocument) BadRequestException(com.azure.cosmos.implementation.BadRequestException) EdcException(org.eclipse.dataspaceconnector.spi.EdcException)

Example 4 with ContractNegotiationDocument

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();
}
Also used : ContractNegotiationDocument(org.eclipse.dataspaceconnector.contract.negotiation.store.model.ContractNegotiationDocument) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with ContractNegotiationDocument

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()));
}
Also used : SortOrder(org.eclipse.dataspaceconnector.spi.query.SortOrder) IntStream(java.util.stream.IntStream) BadRequestException(com.azure.cosmos.implementation.BadRequestException) BeforeEach(org.junit.jupiter.api.BeforeEach) CosmosTestClient(org.eclipse.dataspaceconnector.azure.testfixtures.CosmosTestClient) ContractAgreement(org.eclipse.dataspaceconnector.spi.types.domain.contract.agreement.ContractAgreement) TypeManager(org.eclipse.dataspaceconnector.spi.types.TypeManager) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CosmosDatabase(com.azure.cosmos.CosmosDatabase) PartitionKey(com.azure.cosmos.models.PartitionKey) Scanner(java.util.Scanner) TestFunctions.generateDocument(org.eclipse.dataspaceconnector.contract.negotiation.store.TestFunctions.generateDocument) AfterAll(org.junit.jupiter.api.AfterAll) ContractDefinition(org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractDefinition) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) CosmosDbApiImpl(org.eclipse.dataspaceconnector.azure.cosmos.CosmosDbApiImpl) ContractNegotiation(org.eclipse.dataspaceconnector.spi.types.domain.contract.negotiation.ContractNegotiation) TestFunctions.generateNegotiation(org.eclipse.dataspaceconnector.contract.negotiation.store.TestFunctions.generateNegotiation) ContractOffer(org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractOffer) Policy(org.eclipse.dataspaceconnector.policy.model.Policy) Awaitility.await(org.awaitility.Awaitility.await) CosmosStoredProcedureProperties(com.azure.cosmos.models.CosmosStoredProcedureProperties) RetryPolicy(net.jodah.failsafe.RetryPolicy) EdcException(org.eclipse.dataspaceconnector.spi.EdcException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) QuerySpec(org.eclipse.dataspaceconnector.spi.query.QuerySpec) ContractNegotiationDocument(org.eclipse.dataspaceconnector.contract.negotiation.store.model.ContractNegotiationDocument) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) ContractNegotiationStates(org.eclipse.dataspaceconnector.spi.types.domain.contract.negotiation.ContractNegotiationStates) ChronoUnit(java.time.temporal.ChronoUnit) CosmosContainer(com.azure.cosmos.CosmosContainer) ContractId(org.eclipse.dataspaceconnector.contract.common.ContractId) Comparator(java.util.Comparator) TestFunctions.generateAgreementBuilder(org.eclipse.dataspaceconnector.contract.negotiation.store.TestFunctions.generateAgreementBuilder) TestFunctions.generateNegotiationBuilder(org.eclipse.dataspaceconnector.contract.negotiation.store.TestFunctions.generateNegotiationBuilder) ContractNegotiationDocument(org.eclipse.dataspaceconnector.contract.negotiation.store.model.ContractNegotiationDocument) ContractNegotiation(org.eclipse.dataspaceconnector.spi.types.domain.contract.negotiation.ContractNegotiation) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ContractNegotiationDocument (org.eclipse.dataspaceconnector.contract.negotiation.store.model.ContractNegotiationDocument)8 AzureCosmosDbIntegrationTest (org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest)7 Test (org.junit.jupiter.api.Test)7 PartitionKey (com.azure.cosmos.models.PartitionKey)4 BadRequestException (com.azure.cosmos.implementation.BadRequestException)2 Duration (java.time.Duration)2 EdcException (org.eclipse.dataspaceconnector.spi.EdcException)2 ContractNegotiation (org.eclipse.dataspaceconnector.spi.types.domain.contract.negotiation.ContractNegotiation)2 CosmosContainer (com.azure.cosmos.CosmosContainer)1 CosmosDatabase (com.azure.cosmos.CosmosDatabase)1 CosmosStoredProcedureProperties (com.azure.cosmos.models.CosmosStoredProcedureProperties)1 ChronoUnit (java.time.temporal.ChronoUnit)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Scanner (java.util.Scanner)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 RetryPolicy (net.jodah.failsafe.RetryPolicy)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1