Skip to content

Commit

Permalink
fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt committed Jul 31, 2023
1 parent 4ba9dc9 commit 3e9b8f5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public String name() {
@Provider(isDefault = true)
public FederatedCacheStore defaultCacheStore() {
//todo: converts every criterion into a predicate that is always true. must be changed later!
return new InMemoryFederatedCacheStore(criterion -> offer -> true, new LockManager(new ReentrantReadWriteLock()));
return new InMemoryFederatedCacheStore(new LockManager(new ReentrantReadWriteLock()));
}

@Provider(isDefault = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.eclipse.edc.catalog.spi.CatalogConstants;
import org.eclipse.edc.catalog.spi.FederatedCacheStore;
import org.eclipse.edc.spi.query.Criterion;
import org.eclipse.edc.spi.query.CriterionConverter;
import org.eclipse.edc.spi.query.CriterionToPredicateConverter;
import org.eclipse.edc.util.concurrency.LockManager;

import java.util.Collection;
Expand All @@ -36,11 +36,11 @@
public class InMemoryFederatedCacheStore implements FederatedCacheStore {

private final Map<String, MarkableEntry<Catalog>> cache = new ConcurrentHashMap<>();
private final CriterionConverter<Predicate<Catalog>> converter;
private final CriterionToPredicateConverter converter;
private final LockManager lockManager;

public InMemoryFederatedCacheStore(CriterionConverter<Predicate<Catalog>> converter, LockManager lockManager) {
this.converter = converter;
public InMemoryFederatedCacheStore(LockManager lockManager) {
this.converter = new AlwaysTruePredicateConverter();
this.lockManager = lockManager;
}

Expand Down Expand Up @@ -83,7 +83,6 @@ private static class MarkableEntry<B> {
mark = isMarked;
}


public boolean isMarked() {
return mark;
}
Expand All @@ -93,4 +92,11 @@ public B getEntry() {
}

}

private static class AlwaysTruePredicateConverter implements CriterionToPredicateConverter {
@Override
public <T> Predicate<T> convert(Criterion criterion) {
return i -> true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.eclipse.edc.catalog.store.InMemoryFederatedCacheStore;
import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.spi.query.CriterionConverter;
import org.eclipse.edc.spi.types.domain.asset.Asset;
import org.eclipse.edc.util.concurrency.LockManager;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -30,38 +29,16 @@
import java.util.List;
import java.util.UUID;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Predicate;

import static org.assertj.core.api.Assertions.assertThat;

class InMemoryFederatedCacheStoreTest {

private InMemoryFederatedCacheStore store;

private static Asset createAsset(String id) {
return Asset.Builder.newInstance()
.id(id)
.build();
}

private static ContractOffer createContractOffer(String id, Asset asset) {
return ContractOffer.Builder.newInstance()
.id(id)
.assetId(asset.getId())
.policy(Policy.Builder.newInstance().build())
.build();
}

private static Catalog createEntry(String id, Asset asset) {
var offer = createContractOffer("offer-" + id, asset);
return Catalog.Builder.newInstance().contractOffers(List.of(offer)).id(id)
.property(CatalogConstants.PROPERTY_ORIGINATOR, "http://test.source/" + id).build();
}

@BeforeEach
public void setUp() {
CriterionConverter<Predicate<Catalog>> converter = criterion -> entry -> true;
store = new InMemoryFederatedCacheStore(converter, new LockManager(new ReentrantReadWriteLock()));
store = new InMemoryFederatedCacheStore(new LockManager(new ReentrantReadWriteLock()));
}

@Test
Expand Down Expand Up @@ -159,4 +136,25 @@ void removedMarked_shouldDeleteMarked() {
.doesNotContain(entry1, entry2);

}
}

private Asset createAsset(String id) {
return Asset.Builder.newInstance()
.id(id)
.build();
}

private ContractOffer createContractOffer(String id, Asset asset) {
return ContractOffer.Builder.newInstance()
.id(id)
.assetId(asset.getId())
.policy(Policy.Builder.newInstance().build())
.build();
}

private Catalog createEntry(String id, Asset asset) {
var offer = createContractOffer("offer-" + id, asset);
return Catalog.Builder.newInstance().contractOffers(List.of(offer)).id(id)
.property(CatalogConstants.PROPERTY_ORIGINATOR, "http://test.source/" + id).build();
}

}

0 comments on commit 3e9b8f5

Please sign in to comment.