use of org.eclipse.dataspaceconnector.spi.types.domain.contract.negotiation.ContractNegotiation in project DataSpaceConnector by eclipse-dataspaceconnector.
the class InMemoryContractNegotiationStoreTest method verifyNextForState_avoidsStarvation.
@Test
void verifyNextForState_avoidsStarvation() throws InterruptedException {
for (int i = 0; i < 10; i++) {
ContractNegotiation negotiation = createNegotiation("test-negotiation-" + i);
negotiation.transitionInitial();
store.save(negotiation);
}
var list1 = store.nextForState(ContractNegotiationStates.INITIAL.code(), 5);
// simulate a short delay to generate different timestamps
Thread.sleep(50);
list1.forEach(tp -> store.save(tp));
var list2 = store.nextForState(ContractNegotiationStates.INITIAL.code(), 5);
assertThat(list1).isNotEqualTo(list2).doesNotContainAnyElementsOf(list2);
}
use of org.eclipse.dataspaceconnector.spi.types.domain.contract.negotiation.ContractNegotiation in project DataSpaceConnector by eclipse-dataspaceconnector.
the class InMemoryContractNegotiationStoreTest method verifyOrderingByTimestamp.
@Test
void verifyOrderingByTimestamp() {
for (int i = 0; i < 100; i++) {
ContractNegotiation negotiation = createNegotiation("test-negotiation-" + i);
negotiation.transitionInitial();
store.save(negotiation);
}
List<ContractNegotiation> processes = store.nextForState(ContractNegotiationStates.INITIAL.code(), 50);
assertThat(processes).hasSize(50);
assertThat(processes).allMatch(p -> p.getStateTimestamp() > 0);
}
use of org.eclipse.dataspaceconnector.spi.types.domain.contract.negotiation.ContractNegotiation in project DataSpaceConnector by eclipse-dataspaceconnector.
the class InMemoryContractNegotiationStoreTest method verifyMultipleRequest.
@Test
void verifyMultipleRequest() {
String id1 = UUID.randomUUID().toString();
ContractNegotiation negotiation1 = createNegotiation(id1);
negotiation1.transitionInitial();
store.save(negotiation1);
String id2 = UUID.randomUUID().toString();
ContractNegotiation negotiation2 = createNegotiation(id2);
negotiation2.transitionInitial();
store.save(negotiation2);
ContractNegotiation found1 = store.find(id1);
assertNotNull(found1);
ContractNegotiation found2 = store.find(id2);
assertNotNull(found2);
var found = store.nextForState(ContractNegotiationStates.INITIAL.code(), 3);
assertEquals(2, found.size());
}
use of org.eclipse.dataspaceconnector.spi.types.domain.contract.negotiation.ContractNegotiation in project DataSpaceConnector by eclipse-dataspaceconnector.
the class InMemoryContractNegotiationStoreTest method verifyMultipleRequest.
@Test
void verifyMultipleRequest() {
String id1 = UUID.randomUUID().toString();
ContractNegotiation negotiation1 = createNegotiation(id1);
negotiation1.transitionInitial();
store.save(negotiation1);
String id2 = UUID.randomUUID().toString();
ContractNegotiation negotiation2 = createNegotiation(id2);
negotiation2.transitionInitial();
store.save(negotiation2);
ContractNegotiation found1 = store.find(id1);
assertNotNull(found1);
ContractNegotiation found2 = store.find(id2);
assertNotNull(found2);
var found = store.nextForState(INITIAL.code(), 3);
assertEquals(2, found.size());
}
use of org.eclipse.dataspaceconnector.spi.types.domain.contract.negotiation.ContractNegotiation in project DataSpaceConnector by eclipse-dataspaceconnector.
the class InMemoryContractNegotiationStore method delete.
@Override
public void delete(String processId) {
lockManager.writeLock(() -> {
ContractNegotiation process = negotiationById.remove(processId);
if (process != null) {
var tempCache = new HashMap<Integer, List<ContractNegotiation>>();
stateCache.forEach((key, value) -> {
var list = value.stream().filter(p -> !p.getId().equals(processId)).collect(Collectors.toCollection(ArrayList::new));
tempCache.put(key, list);
});
stateCache.clear();
stateCache.putAll(tempCache);
negotiationByCorrelationId.remove(process.getCorrelationId());
if (process.getContractAgreement() != null) {
contractAgreements.remove(process.getContractAgreement().getId());
}
}
return null;
});
}
Aggregations