Search in sources :

Example 26 with CommitMeta

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

the class AbstractRestMergeTransplant method mergeWithNamespaces.

@ParameterizedTest
@EnumSource(value = ReferenceMode.class, mode = Mode.EXCLUDE, // merge requires the hash
names = "NAME_ONLY")
public void mergeWithNamespaces(ReferenceMode refMode) throws BaseNessieClientServerException {
    Branch base = createBranch("merge-base");
    Branch branch = createBranch("merge-branch");
    Namespace ns = Namespace.parse("a.b.c");
    // create the same namespace on both branches
    getApi().createNamespace().namespace(ns).refName(branch.getName()).create();
    getApi().createNamespace().namespace(ns).refName(base.getName()).create();
    IcebergTable table1 = IcebergTable.of("merge-table1", 42, 42, 42, 42);
    IcebergTable table2 = IcebergTable.of("merge-table2", 43, 43, 43, 43);
    ContentKey key1 = ContentKey.of(ns, "key1");
    ContentKey key2 = ContentKey.of(ns, "key2");
    Branch committed1 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(branch.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-branch1")).operation(Put.of(key1, table1)).commit();
    assertThat(committed1.getHash()).isNotNull();
    Branch committed2 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(committed1.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-branch2")).operation(Put.of(key1, table1, table1)).commit();
    assertThat(committed2.getHash()).isNotNull();
    getApi().commitMultipleOperations().branchName(base.getName()).hash(base.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-main")).operation(Put.of(key2, table2)).commit();
    getApi().mergeRefIntoBranch().branch(base).fromRef(refMode.transform(committed2)).merge();
    LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
    assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly("test-merge-branch2", "test-merge-branch1", "create namespace a.b.c", "test-merge-main", "create namespace a.b.c");
    assertThat(getApi().getEntries().refName(base.getName()).get().getEntries().stream().map(Entry::getName)).containsExactlyInAnyOrder(key1, key2, ContentKey.of(ns.getElements()));
    assertThat(getApi().getNamespace().refName(base.getName()).namespace(ns).get()).isNotNull();
}
Also used : ContentKey(org.projectnessie.model.ContentKey) LogResponse(org.projectnessie.model.LogResponse) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Entry(org.projectnessie.model.EntriesResponse.Entry) Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) CommitMeta(org.projectnessie.model.CommitMeta) Namespace(org.projectnessie.model.Namespace) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with CommitMeta

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

the class AbstractRestNamespace method testNamespaceDeletion.

@Test
public void testNamespaceDeletion() throws BaseNessieClientServerException {
    Branch branch = createBranch("testNamespaceDeletion");
    CommitMultipleOperationsBuilder commit = getApi().commitMultipleOperations().branch(branch).commitMeta(CommitMeta.fromMessage("verifyAllContentAndOperationTypes"));
    contentAndOperationTypes().flatMap(c -> c.globalOperation == null ? Stream.of(c.operation) : Stream.of(c.operation, c.globalOperation)).forEach(commit::operation);
    commit.commit();
    List<Entry> entries = contentAndOperationTypes().filter(c -> c.operation instanceof Put).map(c -> Entry.builder().type(c.type).name(c.operation.getKey()).build()).collect(Collectors.toList());
    for (Entry e : entries) {
        Namespace namespace = e.getName().getNamespace();
        assertThat(getApi().getNamespace().refName(branch.getName()).namespace(namespace).get()).isEqualTo(namespace);
        assertThatThrownBy(() -> getApi().deleteNamespace().refName(branch.getName()).namespace(namespace).delete()).isInstanceOf(NessieNamespaceNotEmptyException.class).hasMessage(String.format("Namespace '%s' is not empty", namespace));
    }
}
Also used : Arrays(java.util.Arrays) NessieNamespaceNotEmptyException(org.projectnessie.error.NessieNamespaceNotEmptyException) LogResponse(org.projectnessie.model.LogResponse) Put(org.projectnessie.model.Operation.Put) NessieNamespaceAlreadyExistsException(org.projectnessie.error.NessieNamespaceAlreadyExistsException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Collectors(java.util.stream.Collectors) Entry(org.projectnessie.model.EntriesResponse.Entry) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) IcebergTable(org.projectnessie.model.IcebergTable) Namespace(org.projectnessie.model.Namespace) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) CommitMeta(org.projectnessie.model.CommitMeta) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) NessieNamespaceNotFoundException(org.projectnessie.error.NessieNamespaceNotFoundException) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Entry(org.projectnessie.model.EntriesResponse.Entry) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) NessieNamespaceNotEmptyException(org.projectnessie.error.NessieNamespaceNotEmptyException) Branch(org.projectnessie.model.Branch) Put(org.projectnessie.model.Operation.Put) Namespace(org.projectnessie.model.Namespace) Test(org.junit.jupiter.api.Test)

Example 28 with CommitMeta

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

the class AbstractRestCommitLog method commitLogExtended.

@ParameterizedTest
@EnumSource(ReferenceMode.class)
public void commitLogExtended(ReferenceMode refMode) throws Exception {
    String branch = "commitLogExtended";
    String firstParent = getApi().createReference().sourceRefName("main").reference(Branch.of(branch, null)).create().getHash();
    int numCommits = 10;
    // Hack for tests running via Quarkus :(
    IntFunction<String> c1 = i -> refMode.name() + "-c1-" + i;
    IntFunction<String> c2 = i -> refMode.name() + "-c2-" + i;
    List<String> hashes = IntStream.rangeClosed(1, numCommits).mapToObj(i -> {
        try {
            String head = getApi().getReference().refName(branch).get().getHash();
            return getApi().commitMultipleOperations().operation(Put.of(ContentKey.of("k" + i), IcebergTable.of("m" + i, i, i, i, i, c1.apply(i)))).operation(Put.of(ContentKey.of("key" + i), IcebergTable.of("meta" + i, i, i, i, i, c2.apply(i)))).operation(Delete.of(ContentKey.of("delete" + i))).operation(Unchanged.of(ContentKey.of("key" + i))).commitMeta(CommitMeta.fromMessage("Commit #" + i)).branchName(branch).hash(head).commit().getHash();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }).collect(Collectors.toList());
    List<String> parentHashes = Stream.concat(Stream.of(firstParent), hashes.subList(0, 9).stream()).collect(Collectors.toList());
    Reference branchRef = getApi().getReference().refName(branch).get();
    assertThat(Lists.reverse(getApi().getCommitLog().untilHash(firstParent).reference(refMode.transform(branchRef)).get().getLogEntries())).allSatisfy(c -> {
        assertThat(c.getOperations()).isNull();
        assertThat(c.getParentCommitHash()).isNull();
    }).extracting(e -> e.getCommitMeta().getHash()).containsExactlyElementsOf(hashes);
    List<LogEntry> commits = Lists.reverse(getApi().getCommitLog().fetch(FetchOption.ALL).reference(refMode.transform(branchRef)).untilHash(firstParent).get().getLogEntries());
    assertThat(IntStream.rangeClosed(1, numCommits)).allSatisfy(i -> {
        LogEntry c = commits.get(i - 1);
        assertThat(c).extracting(e -> e.getCommitMeta().getMessage(), e -> e.getCommitMeta().getHash(), LogEntry::getParentCommitHash, LogEntry::getOperations).containsExactly("Commit #" + i, hashes.get(i - 1), parentHashes.get(i - 1), Arrays.asList(Delete.of(ContentKey.of("delete" + i)), Put.of(ContentKey.of("k" + i), IcebergTable.of("m" + i, i, i, i, i, c1.apply(i))), Put.of(ContentKey.of("key" + i), IcebergTable.of("meta" + i, i, i, i, i, c2.apply(i)))));
    });
}
Also used : IntStream(java.util.stream.IntStream) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) LogResponse(org.projectnessie.model.LogResponse) Put(org.projectnessie.model.Operation.Put) Unchanged(org.projectnessie.model.Operation.Unchanged) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) EnumSource(org.junit.jupiter.params.provider.EnumSource) OptionalInt(java.util.OptionalInt) Reference(org.projectnessie.model.Reference) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommitMeta(org.projectnessie.model.CommitMeta) IntFunction(java.util.function.IntFunction) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) FetchOption(org.projectnessie.api.params.FetchOption) ChronoUnit(java.time.temporal.ChronoUnit) Stream(java.util.stream.Stream) IcebergView(org.projectnessie.model.IcebergView) Delete(org.projectnessie.model.Operation.Delete) StreamingUtil(org.projectnessie.client.StreamingUtil) IcebergTable(org.projectnessie.model.IcebergTable) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) Collections(java.util.Collections) Reference(org.projectnessie.model.Reference) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) LogEntry(org.projectnessie.model.LogResponse.LogEntry) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with CommitMeta

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

the class AbstractRestContents method verifyAllContentAndOperationTypes.

@Test
public void verifyAllContentAndOperationTypes() throws BaseNessieClientServerException {
    Branch branch = createBranch("contentAndOperationAll");
    CommitMultipleOperationsBuilder commit = getApi().commitMultipleOperations().branch(branch).commitMeta(CommitMeta.fromMessage("verifyAllContentAndOperationTypes"));
    contentAndOperationTypes().flatMap(c -> c.globalOperation == null ? Stream.of(c.operation) : Stream.of(c.operation, c.globalOperation)).forEach(commit::operation);
    commit.commit();
    List<Entry> entries = getApi().getEntries().refName(branch.getName()).get().getEntries();
    List<Entry> expect = contentAndOperationTypes().filter(c -> c.operation instanceof Put).map(c -> Entry.builder().type(c.type).name(c.operation.getKey()).build()).collect(Collectors.toList());
    assertThat(entries).containsExactlyInAnyOrderElementsOf(expect);
}
Also used : Put(org.projectnessie.model.Operation.Put) Unchanged(org.projectnessie.model.Operation.Unchanged) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Entry(org.projectnessie.model.EntriesResponse.Entry) Collections.singletonList(java.util.Collections.singletonList) Type(org.projectnessie.model.Content.Type) Map(java.util.Map) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) MethodSource(org.junit.jupiter.params.provider.MethodSource) Operation(org.projectnessie.model.Operation) Collections.emptyList(java.util.Collections.emptyList) Branch(org.projectnessie.model.Branch) ImmutableDeltaLakeTable(org.projectnessie.model.ImmutableDeltaLakeTable) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) IcebergView(org.projectnessie.model.IcebergView) Delete(org.projectnessie.model.Operation.Delete) IcebergTable(org.projectnessie.model.IcebergTable) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) Entry(org.projectnessie.model.EntriesResponse.Entry) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) Branch(org.projectnessie.model.Branch) Put(org.projectnessie.model.Operation.Put) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with CommitMeta

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

the class AbstractRestReferences method verifyMetadataProperties.

void verifyMetadataProperties(Tag tag) throws NessieNotFoundException {
    List<LogEntry> commits = getApi().getCommitLog().refName(tag.getName()).maxRecords(1).get().getLogEntries();
    assertThat(commits).hasSize(1);
    CommitMeta commitMeta = commits.get(0).getCommitMeta();
    ReferenceMetadata referenceMetadata = tag.getMetadata();
    assertThat(referenceMetadata).isNotNull();
    assertThat(referenceMetadata.getNumCommitsAhead()).isNull();
    assertThat(referenceMetadata.getNumCommitsBehind()).isNull();
    assertThat(referenceMetadata.getCommitMetaOfHEAD()).isEqualTo(commitMeta);
    assertThat(referenceMetadata.getCommonAncestorHash()).isNull();
    assertThat(referenceMetadata.getNumTotalCommits()).isEqualTo(10);
}
Also used : CommitMeta(org.projectnessie.model.CommitMeta) LogEntry(org.projectnessie.model.LogResponse.LogEntry) ReferenceMetadata(org.projectnessie.model.ReferenceMetadata)

Aggregations

CommitMeta (org.projectnessie.model.CommitMeta)37 Branch (org.projectnessie.model.Branch)17 LogEntry (org.projectnessie.model.LogResponse.LogEntry)15 Test (org.junit.jupiter.api.Test)14 IcebergTable (org.projectnessie.model.IcebergTable)14 ContentKey (org.projectnessie.model.ContentKey)13 LogResponse (org.projectnessie.model.LogResponse)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 Content (org.projectnessie.model.Content)10 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)8 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)8 Reference (org.projectnessie.model.Reference)7 ArrayList (java.util.ArrayList)6 Entry (org.projectnessie.model.EntriesResponse.Entry)6 Operation (org.projectnessie.model.Operation)6 Put (org.projectnessie.model.Operation.Put)6 Stream (java.util.stream.Stream)5