Search in sources :

Example 56 with Branch

use of org.projectnessie.model.Branch 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 57 with Branch

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

the class AbstractRestMisc method checkServerErrorPropagation.

@Test
public void checkServerErrorPropagation() throws BaseNessieClientServerException {
    Branch branch = createBranch("bar");
    assertThatThrownBy(() -> getApi().createReference().sourceRefName("main").reference(branch).create()).isInstanceOf(NessieReferenceAlreadyExistsException.class).hasMessageContaining("already exists");
    assertThatThrownBy(() -> getApi().commitMultipleOperations().branch(branch).commitMeta(CommitMeta.builder().author("author").message("committed-by-test").committer("disallowed-client-side-committer").build()).operation(Unchanged.of(ContentKey.of("table"))).commit()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Cannot set the committer on the client side.");
}
Also used : NessieBadRequestException(org.projectnessie.error.NessieBadRequestException) Branch(org.projectnessie.model.Branch) NessieReferenceAlreadyExistsException(org.projectnessie.error.NessieReferenceAlreadyExistsException) Test(org.junit.jupiter.api.Test)

Example 58 with Branch

use of org.projectnessie.model.Branch 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 59 with Branch

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

the class AbstractRest method tearDown.

@AfterEach
public void tearDown() throws Exception {
    Branch defaultBranch = api.getDefaultBranch();
    for (Reference ref : api.getAllReferences().get().getReferences()) {
        if (ref.getName().equals(defaultBranch.getName())) {
            continue;
        }
        if (ref instanceof Branch) {
            api.deleteBranch().branch((Branch) ref).delete();
        } else if (ref instanceof Tag) {
            api.deleteTag().tag((Tag) ref).delete();
        }
    }
    api.close();
}
Also used : Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference) Tag(org.projectnessie.model.Tag) AfterEach(org.junit.jupiter.api.AfterEach)

Example 60 with Branch

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

the class AbstractRest method createBranch.

protected Branch createBranch(String name, Branch from) throws BaseNessieClientServerException {
    Branch expectedBranch;
    String srcBranchName;
    if (from == null) {
        Branch main = getApi().getDefaultBranch();
        expectedBranch = Branch.of(name, main.getHash());
        srcBranchName = "main";
    } else {
        expectedBranch = Branch.of(name, from.getHash());
        srcBranchName = from.getName();
    }
    Reference created = getApi().createReference().sourceRefName(srcBranchName).reference(Branch.of(name, expectedBranch.getHash())).create();
    assertThat(created).isEqualTo(expectedBranch);
    return expectedBranch;
}
Also used : Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference)

Aggregations

Branch (org.projectnessie.model.Branch)81 Test (org.junit.jupiter.api.Test)56 IcebergTable (org.projectnessie.model.IcebergTable)30 ContentKey (org.projectnessie.model.ContentKey)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 LogResponse (org.projectnessie.model.LogResponse)19 Reference (org.projectnessie.model.Reference)19 CommitMeta (org.projectnessie.model.CommitMeta)18 Instant (java.time.Instant)16 LogEntry (org.projectnessie.model.LogResponse.LogEntry)13 List (java.util.List)12 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)12 Tag (org.projectnessie.model.Tag)12 Collectors (java.util.stream.Collectors)11 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)11 Content (org.projectnessie.model.Content)11 Entry (org.projectnessie.model.EntriesResponse.Entry)10 Put (org.projectnessie.model.Operation.Put)10 IcebergView (org.projectnessie.model.IcebergView)9 Map (java.util.Map)8