Search in sources :

Example 21 with ContentKey

use of org.projectnessie.model.ContentKey in project nessie by projectnessie.

the class ITUpgradePath method commitLog.

@Test
@Order(104)
void commitLog() {
    assertThat(api.getAllReferences().get().getReferences().stream().filter(r -> r.getName().startsWith(VERSION_BRANCH_PREFIX))).isNotEmpty().allSatisfy(ref -> {
        String versionFromRef = ref.getName().substring(VERSION_BRANCH_PREFIX.length());
        LogResponse commitLog = api.getCommitLog().refName(ref.getName()).get();
        String commitMessage = "hello world " + versionFromRef;
        assertThat(commitLog.getLogEntries()).hasSize(1).map(LogEntry::getCommitMeta).map(CommitMeta::getMessage).containsExactly(commitMessage);
    }).allSatisfy(ref -> {
        String versionFromRef = ref.getName().substring(VERSION_BRANCH_PREFIX.length());
        ContentKey key = ContentKey.of("my", "tables", "table_name");
        IcebergTable content = IcebergTable.of("metadata-location", 42L, 43, 44, 45, "content-id-" + versionFromRef);
        Map<ContentKey, Content> contents = api.getContent().reference(ref).key(key).get();
        assertThat(contents).containsExactly(entry(key, content));
    });
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) NessieVersion(org.projectnessie.tools.compatibility.api.NessieVersion) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Order(org.junit.jupiter.api.Order) NessieConflictException(org.projectnessie.error.NessieConflictException) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Content(org.projectnessie.model.Content) Branch(org.projectnessie.model.Branch) Set(java.util.Set) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Collectors(java.util.stream.Collectors) NessieApiV1(org.projectnessie.client.api.NessieApiV1) Test(org.junit.jupiter.api.Test) NessieUpgradesExtension(org.projectnessie.tools.compatibility.internal.NessieUpgradesExtension) List(java.util.List) Delete(org.projectnessie.model.Operation.Delete) StreamingUtil(org.projectnessie.client.StreamingUtil) Entry(java.util.Map.Entry) DatabaseAdapterConfig(org.projectnessie.versioned.persist.adapter.DatabaseAdapterConfig) ContentKey(org.projectnessie.model.ContentKey) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) NonTransactionalDatabaseAdapterConfig(org.projectnessie.versioned.persist.nontx.NonTransactionalDatabaseAdapterConfig) Version(org.projectnessie.tools.compatibility.api.Version) IntStream(java.util.stream.IntStream) LogResponse(org.projectnessie.model.LogResponse) Put(org.projectnessie.model.Operation.Put) RefLogResponseEntry(org.projectnessie.model.RefLogResponse.RefLogResponseEntry) HashMap(java.util.HashMap) OptionalInt(java.util.OptionalInt) Reference(org.projectnessie.model.Reference) ArrayList(java.util.ArrayList) VersionCondition(org.projectnessie.tools.compatibility.api.VersionCondition) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) CommitMeta(org.projectnessie.model.CommitMeta) NessieAPI(org.projectnessie.tools.compatibility.api.NessieAPI) Tuple(org.assertj.core.groups.Tuple) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Assumptions.assumeThat(org.assertj.core.api.Assumptions.assumeThat) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Assertions.entry(org.assertj.core.api.Assertions.entry) MethodOrderer(org.junit.jupiter.api.MethodOrderer) AfterEach(org.junit.jupiter.api.AfterEach) IcebergTable(org.projectnessie.model.IcebergTable) Collections(java.util.Collections) ContentKey(org.projectnessie.model.ContentKey) LogResponse(org.projectnessie.model.LogResponse) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) CommitMeta(org.projectnessie.model.CommitMeta) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 22 with ContentKey

use of org.projectnessie.model.ContentKey in project nessie by projectnessie.

the class AbstractRestEntries method filterEntriesByType.

@ParameterizedTest
@EnumSource(ReferenceMode.class)
public void filterEntriesByType(ReferenceMode refMode) throws BaseNessieClientServerException {
    Branch branch = createBranch("filterTypes");
    ContentKey a = ContentKey.of("a");
    ContentKey b = ContentKey.of("b");
    IcebergTable tam = IcebergTable.of("path1", 42, 42, 42, 42);
    IcebergView tb = IcebergView.of("pathx", 1, 1, "select * from table", "Dremio");
    getApi().commitMultipleOperations().branch(branch).operation(Put.of(a, tam)).commitMeta(CommitMeta.fromMessage("commit 1")).commit();
    branch = getApi().commitMultipleOperations().branch(branch).operation(Put.of(b, tb)).commitMeta(CommitMeta.fromMessage("commit 2")).commit();
    List<Entry> entries = getApi().getEntries().reference(refMode.transform(branch)).get().getEntries();
    List<Entry> expected = asList(Entry.builder().name(a).type(Type.ICEBERG_TABLE).build(), Entry.builder().name(b).type(Type.ICEBERG_VIEW).build());
    assertThat(entries).containsExactlyInAnyOrderElementsOf(expected);
    entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.contentType=='ICEBERG_TABLE'").get().getEntries();
    assertEquals(singletonList(expected.get(0)), entries);
    entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.contentType=='ICEBERG_VIEW'").get().getEntries();
    assertEquals(singletonList(expected.get(1)), entries);
    entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.contentType in ['ICEBERG_TABLE', 'ICEBERG_VIEW']").get().getEntries();
    assertThat(entries).containsExactlyInAnyOrderElementsOf(expected);
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Entry(org.projectnessie.model.EntriesResponse.Entry) Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) IcebergView(org.projectnessie.model.IcebergView) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with ContentKey

use of org.projectnessie.model.ContentKey in project nessie by projectnessie.

the class AbstractRestEntries method filterEntriesByNamespaceAndPrefixDepth.

@ParameterizedTest
@EnumSource(ReferenceMode.class)
public void filterEntriesByNamespaceAndPrefixDepth(ReferenceMode refMode) throws BaseNessieClientServerException {
    Branch branch = createBranch("filterEntriesByNamespaceAndPrefixDepth");
    ContentKey first = ContentKey.of("a", "b", "c", "firstTable");
    ContentKey second = ContentKey.of("a", "b", "c", "secondTable");
    ContentKey third = ContentKey.of("a", "thirdTable");
    ContentKey fourth = ContentKey.of("a", "b", "fourthTable");
    ContentKey fifth = ContentKey.of("a", "boo", "fifthTable");
    ContentKey withoutNamespace = ContentKey.of("withoutNamespace");
    List<ContentKey> keys = ImmutableList.of(first, second, third, fourth, fifth, withoutNamespace);
    for (int i = 0; i < keys.size(); i++) {
        getApi().commitMultipleOperations().branch(branch).operation(Put.of(keys.get(i), IcebergTable.of("path" + i, 42, 42, 42, 42))).commitMeta(CommitMeta.fromMessage("commit " + i)).commit();
    }
    branch = (Branch) getApi().getReference().refName(branch.getName()).get();
    Reference reference = refMode.transform(branch);
    List<Entry> entries = getApi().getEntries().reference(reference).namespaceDepth(0).get().getEntries();
    assertThat(entries).isNotNull().hasSize(6);
    entries = getApi().getEntries().reference(reference).namespaceDepth(0).filter("entry.namespace.matches('a(\\\\.|$)')").get().getEntries();
    assertThat(entries).isNotNull().hasSize(5);
    entries = getApi().getEntries().reference(reference).namespaceDepth(1).filter("entry.namespace.matches('a(\\\\.|$)')").get().getEntries();
    assertThat(entries).hasSize(1);
    assertThat(entries.get(0)).matches(e -> e.getType().equals(Type.NAMESPACE)).matches(e -> e.getName().equals(ContentKey.of("a")));
    entries = getApi().getEntries().reference(reference).namespaceDepth(2).filter("entry.namespace.matches('a(\\\\.|$)')").get().getEntries();
    assertThat(entries).hasSize(3);
    assertThat(entries.get(2)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "thirdTable")));
    assertThat(entries.get(1)).matches(e -> e.getType().equals(Type.NAMESPACE)).matches(e -> e.getName().equals(ContentKey.of("a", "b")));
    assertThat(entries.get(0)).matches(e -> e.getType().equals(Type.NAMESPACE)).matches(e -> e.getName().equals(ContentKey.of("a", "boo")));
    entries = getApi().getEntries().reference(reference).namespaceDepth(3).filter("entry.namespace.matches('a\\\\.b(\\\\.|$)')").get().getEntries();
    assertThat(entries).hasSize(2);
    assertThat(entries.get(1)).matches(e -> e.getType().equals(Type.NAMESPACE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "c")));
    assertThat(entries.get(0)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "fourthTable")));
    entries = getApi().getEntries().reference(reference).namespaceDepth(4).filter("entry.namespace.matches('a\\\\.b\\\\.c(\\\\.|$)')").get().getEntries();
    assertThat(entries).hasSize(2);
    assertThat(entries.get(1)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "c", "firstTable")));
    assertThat(entries.get(0)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "c", "secondTable")));
    entries = getApi().getEntries().reference(reference).namespaceDepth(5).filter("entry.namespace.matches('(\\\\.|$)')").get().getEntries();
    assertThat(entries).isEmpty();
    entries = getApi().getEntries().reference(reference).namespaceDepth(3).filter("entry.namespace.matches('(\\\\.|$)')").get().getEntries();
    assertThat(entries).hasSize(3);
    assertThat(entries.get(2)).matches(e -> e.getType().equals(Type.NAMESPACE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "c")));
    assertThat(entries.get(1)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "b", "fourthTable")));
    assertThat(entries.get(0)).matches(e -> e.getType().equals(Type.ICEBERG_TABLE)).matches(e -> e.getName().equals(ContentKey.of("a", "boo", "fifthTable")));
    assumeTrue(ReferenceMode.DETACHED != refMode);
    // check that implicit namespaces are properly detected
    checkNamespaces(reference, Arrays.asList("a", "a.b", "a.boo", "a.b.c"), Arrays.asList(first, second, third, fourth, fifth));
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Arrays(java.util.Arrays) NessieNamespaceNotEmptyException(org.projectnessie.error.NessieNamespaceNotEmptyException) Put(org.projectnessie.model.Operation.Put) NessieNamespaceAlreadyExistsException(org.projectnessie.error.NessieNamespaceAlreadyExistsException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) EnumSource(org.junit.jupiter.params.provider.EnumSource) Entry(org.projectnessie.model.EntriesResponse.Entry) Reference(org.projectnessie.model.Reference) Collections.singletonList(java.util.Collections.singletonList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) Arrays.asList(java.util.Arrays.asList) Type(org.projectnessie.model.Content.Type) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommitMeta(org.projectnessie.model.CommitMeta) NessieNamespaceNotFoundException(org.projectnessie.error.NessieNamespaceNotFoundException) Branch(org.projectnessie.model.Branch) Collectors(java.util.stream.Collectors) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) IcebergView(org.projectnessie.model.IcebergView) IcebergTable(org.projectnessie.model.IcebergTable) Namespace(org.projectnessie.model.Namespace) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) Entry(org.projectnessie.model.EntriesResponse.Entry) Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with ContentKey

use of org.projectnessie.model.ContentKey in project nessie by projectnessie.

the class AbstractRestInvalidRefs method testInvalidNamedRefs.

@Test
public void testInvalidNamedRefs() {
    ContentKey key = ContentKey.of("x");
    String invalidRef = "1234567890123456";
    assertThatThrownBy(() -> getApi().getCommitLog().refName(invalidRef).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE);
    assertThatThrownBy(() -> getApi().getEntries().refName(invalidRef).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE);
    assertThatThrownBy(() -> getApi().getContent().key(key).refName(invalidRef).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE);
    assertThatThrownBy(() -> getApi().getContent().refName(invalidRef).key(key).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE);
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Test(org.junit.jupiter.api.Test)

Example 25 with ContentKey

use of org.projectnessie.model.ContentKey in project nessie by projectnessie.

the class AbstractRestInvalidWithHttp method invalidHashes.

@ParameterizedTest
@CsvSource({ "abc'" + COMMA_VALID_HASH_1, ".foo" + COMMA_VALID_HASH_2, "abc'def'..'blah" + COMMA_VALID_HASH_2, "abc'de..blah" + COMMA_VALID_HASH_3, "abc'de@{blah" + COMMA_VALID_HASH_3 })
public void invalidHashes(String invalidHashIn, String validHash) {
    // CsvSource maps an empty string as null
    String invalidHash = invalidHashIn != null ? invalidHashIn : "";
    String validBranchName = "hello";
    ContentKey key = ContentKey.of("x");
    Tag tag = Tag.of("valid", validHash);
    String opsCountMsg = ".operations.operations: size must be between 1 and 2147483647";
    assertAll(() -> assertThatThrownBy(() -> getApi().commitMultipleOperations().branchName(validBranchName).hash(invalidHash).commitMeta(CommitMeta.fromMessage("")).commit()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hash: " + HASH_MESSAGE).hasMessageContaining(opsCountMsg), () -> assertThatThrownBy(() -> getApi().deleteBranch().branchName(validBranchName).hash(invalidHash).delete()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().assignTag().tagName(validBranchName).hash(invalidHash).assignTo(tag).assign()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".oldHash: " + HASH_MESSAGE), () -> {
        if (null != getHttpClient()) {
            assertThatThrownBy(() -> getHttpClient().newRequest().path("trees/branch/{branchName}/merge").resolveTemplate("branchName", validBranchName).queryParam("expectedHash", invalidHash).post(null)).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining("mergeRefIntoBranch.merge: must not be null").hasMessageContaining(".hash: " + HASH_MESSAGE);
        }
    }, () -> assertThatThrownBy(() -> getApi().mergeRefIntoBranch().branchName(validBranchName).hash(invalidHash).fromRef(getApi().getDefaultBranch()).merge()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().deleteTag().tagName(validBranchName).hash(invalidHash).delete()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().transplantCommitsIntoBranch().branchName(validBranchName).hash(invalidHash).fromRefName("main").hashesToTransplant(singletonList(getApi().getReference().refName("main").get().getHash())).transplant()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().getContent().refName(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".request.requestedKeys: size must be between 1 and 2147483647").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getContent().refName(validBranchName).hashOnRef(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".request.requestedKeys: size must be between 1 and 2147483647").hasMessageContaining(".hashOnRef: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().getContent().key(key).refName(validBranchName).hashOnRef(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hashOnRef: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().getCommitLog().refName(validBranchName).untilHash(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".params.startHash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().getCommitLog().refName(validBranchName).hashOnRef(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".params.endHash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().getEntries().refName(validBranchName).hashOnRef(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".params.hashOnRef: " + HASH_MESSAGE));
}
Also used : ContentKey(org.projectnessie.model.ContentKey) NessieBadRequestException(org.projectnessie.error.NessieBadRequestException) Tag(org.projectnessie.model.Tag) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ContentKey (org.projectnessie.model.ContentKey)35 Branch (org.projectnessie.model.Branch)20 Test (org.junit.jupiter.api.Test)15 Content (org.projectnessie.model.Content)15 IcebergTable (org.projectnessie.model.IcebergTable)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 CommitMeta (org.projectnessie.model.CommitMeta)10 Put (org.projectnessie.model.Operation.Put)7 Map (java.util.Map)6 Entry (org.projectnessie.model.EntriesResponse.Entry)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 NessieApiV1 (org.projectnessie.client.api.NessieApiV1)5 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)5 LogResponse (org.projectnessie.model.LogResponse)5 Reference (org.projectnessie.model.Reference)5 HashMap (java.util.HashMap)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)4 LogEntry (org.projectnessie.model.LogResponse.LogEntry)4