-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: enable federated catalog cache SQL variant #1432
Merged
paullatzelsperger
merged 1 commit into
eclipse-tractusx:main
from
wolf4ood:feat/1429_fc_sql_persistence
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...rg/eclipse/tractusx/edc/postgresql/migration/FederatedCatalogCacheMigrationExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
package org.eclipse.tractusx.edc.postgresql.migration; | ||
|
||
public class FederatedCatalogCacheMigrationExtension extends AbstractPostgresqlMigrationExtension { | ||
private static final String NAME_SUBSYSTEM = "federatedcatalog"; | ||
|
||
@Override | ||
protected String getSubsystemName() { | ||
return NAME_SUBSYSTEM; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...tgresql/migration/federatedcatalog/V0_0_1__Init_FederatedCatalogCache_Database_Schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- | ||
-- Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
-- | ||
-- This program and the accompanying materials are made available under the | ||
-- terms of the Apache License, Version 2.0 which is available at | ||
-- https://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
-- | ||
-- Contributors: | ||
-- Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
-- | ||
|
||
-- | ||
-- table: edc_federated_catalog | ||
-- | ||
|
||
CREATE TABLE IF NOT EXISTS edc_federated_catalog | ||
( | ||
id VARCHAR PRIMARY KEY NOT NULL, | ||
catalog JSON, | ||
marked BOOLEAN DEFAULT FALSE | ||
); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
...alog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/FederatedCatalogTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
package org.eclipse.tractusx.edc.tests.catalog; | ||
|
||
import org.eclipse.edc.crawler.spi.TargetNode; | ||
import org.eclipse.edc.crawler.spi.TargetNodeDirectory; | ||
import org.eclipse.edc.junit.annotations.EndToEndTest; | ||
import org.eclipse.edc.junit.annotations.PostgresqlIntegrationTest; | ||
import org.eclipse.edc.junit.extensions.RuntimeExtension; | ||
import org.eclipse.tractusx.edc.tests.participant.TransferParticipant; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static io.restassured.http.ContentType.JSON; | ||
import static org.awaitility.Awaitility.await; | ||
import static org.eclipse.edc.connector.controlplane.test.system.utils.PolicyFixtures.noConstraintPolicy; | ||
import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.CONSUMER_BPN; | ||
import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.CONSUMER_NAME; | ||
import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PROVIDER_BPN; | ||
import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PROVIDER_NAME; | ||
import static org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase.ASYNC_POLL_INTERVAL; | ||
import static org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase.ASYNC_TIMEOUT; | ||
import static org.eclipse.tractusx.edc.tests.runtimes.Runtimes.memoryRuntime; | ||
import static org.eclipse.tractusx.edc.tests.runtimes.Runtimes.pgRuntime; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
public class FederatedCatalogTest { | ||
|
||
protected static final TransferParticipant CONSUMER = TransferParticipant.Builder.newInstance() | ||
.name(CONSUMER_NAME) | ||
.id(CONSUMER_BPN) | ||
.build(); | ||
|
||
|
||
protected static final TransferParticipant PROVIDER = TransferParticipant.Builder.newInstance() | ||
.name(PROVIDER_NAME) | ||
.id(PROVIDER_BPN) | ||
.build(); | ||
|
||
abstract static class Tests { | ||
|
||
@Test | ||
@DisplayName("Consumer gets cached catalog with provider entry") | ||
void requestCatalog_fulfillsPolicy_shouldReturnOffer() { | ||
|
||
// arrange | ||
PROVIDER.createAsset("test-asset"); | ||
var ap = PROVIDER.createPolicyDefinition(noConstraintPolicy()); | ||
var cp = PROVIDER.createPolicyDefinition(noConstraintPolicy()); | ||
PROVIDER.createContractDefinition("test-asset", "test-def", ap, cp); | ||
|
||
|
||
await().pollInterval(ASYNC_POLL_INTERVAL) | ||
.atMost(ASYNC_TIMEOUT) | ||
.untilAsserted(() -> { | ||
// act | ||
CONSUMER.getFederatedCatalog() | ||
.log().ifError() | ||
.statusCode(200) | ||
.contentType(JSON) | ||
.body("size()", is(1)) | ||
.body("[0].'http://www.w3.org/ns/dcat#dataset'.'@id'", equalTo("test-asset")); | ||
}); | ||
} | ||
} | ||
|
||
static class TestTargetNodeDirectory implements TargetNodeDirectory { | ||
|
||
private final List<TransferParticipant> participants; | ||
|
||
TestTargetNodeDirectory(List<TransferParticipant> participants) { | ||
this.participants = participants; | ||
} | ||
|
||
@Override | ||
public List<TargetNode> getAll() { | ||
return participants.stream() | ||
.map(p -> new TargetNode(p.getDid(), p.getBpn(), p.getProtocolEndpoint().getUrl().toString(), List.of("dataspace-protocol-http"))) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public void insert(TargetNode node) { | ||
|
||
} | ||
} | ||
|
||
@Nested | ||
@EndToEndTest | ||
class InMemory extends Tests { | ||
|
||
@RegisterExtension | ||
protected static final RuntimeExtension CONSUMER_RUNTIME = memoryRuntime(CONSUMER.getName(), CONSUMER.getBpn(), CONSUMER.getConfiguration()); | ||
|
||
@RegisterExtension | ||
protected static final RuntimeExtension PROVIDER_RUNTIME = memoryRuntime(PROVIDER.getName(), PROVIDER.getBpn(), PROVIDER.getConfiguration()); | ||
|
||
|
||
static { | ||
CONSUMER_RUNTIME.registerServiceMock(TargetNodeDirectory.class, new TestTargetNodeDirectory(List.of(PROVIDER))); | ||
} | ||
} | ||
|
||
@Nested | ||
@PostgresqlIntegrationTest | ||
class Postgres extends Tests { | ||
|
||
@RegisterExtension | ||
protected static final RuntimeExtension CONSUMER_RUNTIME = pgRuntime(CONSUMER.getName(), CONSUMER.getBpn(), CONSUMER.getConfiguration()); | ||
|
||
@RegisterExtension | ||
protected static final RuntimeExtension PROVIDER_RUNTIME = pgRuntime(PROVIDER.getName(), PROVIDER.getBpn(), PROVIDER.getConfiguration()); | ||
|
||
static { | ||
CONSUMER_RUNTIME.registerServiceMock(TargetNodeDirectory.class, new TestTargetNodeDirectory(List.of(PROVIDER))); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Missing Override annotation Note