Search in sources :

Example 1 with Entry

use of org.projectnessie.model.EntriesResponse.Entry in project nessie by projectnessie.

the class AbstractRestNamespace method testNamespaceMerge.

@Test
public void testNamespaceMerge() 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();
    base = (Branch) getApi().getReference().refName(base.getName()).get();
    branch = (Branch) getApi().getReference().refName(branch.getName()).get();
    getApi().mergeRefIntoBranch().branch(base).fromRef(branch).merge();
    LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
    String expectedCommitMsg = "create namespace a.b.c";
    assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly(expectedCommitMsg, expectedCommitMsg);
    assertThat(getApi().getEntries().refName(base.getName()).get().getEntries().stream().map(Entry::getName)).containsExactly(ContentKey.of(ns.getElements()));
    assertThat(getApi().getNamespace().refName(base.getName()).namespace(ns).get()).isNotNull();
}
Also used : LogResponse(org.projectnessie.model.LogResponse) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Entry(org.projectnessie.model.EntriesResponse.Entry) Branch(org.projectnessie.model.Branch) CommitMeta(org.projectnessie.model.CommitMeta) Namespace(org.projectnessie.model.Namespace) Test(org.junit.jupiter.api.Test)

Example 2 with Entry

use of org.projectnessie.model.EntriesResponse.Entry in project nessie by projectnessie.

the class AbstractRestNamespace method testNamespaceMergeWithConflict.

@Test
public void testNamespaceMergeWithConflict() throws BaseNessieClientServerException {
    Branch base = createBranch("merge-base");
    Branch branch = createBranch("merge-branch");
    Namespace ns = Namespace.parse("a.b.c");
    // create a namespace on the base branch
    getApi().createNamespace().namespace(ns).refName(base.getName()).create();
    base = (Branch) getApi().getReference().refName(base.getName()).get();
    // create a table with the same name on the other branch
    IcebergTable table = IcebergTable.of("merge-table1", 42, 42, 42, 42);
    branch = getApi().commitMultipleOperations().branchName(branch.getName()).hash(branch.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-branch1")).operation(Put.of(ContentKey.of("a", "b", "c"), table)).commit();
    Branch finalBase = base;
    Branch finalBranch = branch;
    assertThatThrownBy(() -> getApi().mergeRefIntoBranch().branch(finalBase).fromRef(finalBranch).merge()).isInstanceOf(NessieReferenceConflictException.class).hasMessage("The following keys have been changed in conflict: 'a.b.c'");
    LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
    // merging should not have been possible ("test-merge-branch1" shouldn't be in the commits)
    assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly("create namespace a.b.c");
    List<Entry> entries = getApi().getEntries().refName(base.getName()).get().getEntries();
    assertThat(entries.stream().map(Entry::getName)).containsExactly(ContentKey.of(ns.getElements()));
    assertThat(getApi().getNamespace().refName(base.getName()).namespace(ns).get()).isNotNull();
}
Also used : 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) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) CommitMeta(org.projectnessie.model.CommitMeta) Namespace(org.projectnessie.model.Namespace) Test(org.junit.jupiter.api.Test)

Example 3 with Entry

use of org.projectnessie.model.EntriesResponse.Entry in project nessie by projectnessie.

the class AbstractRestEntries method filterEntriesByNamespace.

@ParameterizedTest
@EnumSource(ReferenceMode.class)
public void filterEntriesByNamespace(ReferenceMode refMode) throws BaseNessieClientServerException {
    Branch branch = createBranch("filterEntriesByNamespace");
    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", "fourthTable");
    getApi().commitMultipleOperations().branch(branch).operation(Put.of(first, IcebergTable.of("path1", 42, 42, 42, 42))).commitMeta(CommitMeta.fromMessage("commit 1")).commit();
    getApi().commitMultipleOperations().branch(branch).operation(Put.of(second, IcebergTable.of("path2", 42, 42, 42, 42))).commitMeta(CommitMeta.fromMessage("commit 2")).commit();
    getApi().commitMultipleOperations().branch(branch).operation(Put.of(third, IcebergTable.of("path3", 42, 42, 42, 42))).commitMeta(CommitMeta.fromMessage("commit 3")).commit();
    branch = getApi().commitMultipleOperations().branch(branch).operation(Put.of(fourth, IcebergTable.of("path4", 42, 42, 42, 42))).commitMeta(CommitMeta.fromMessage("commit 4")).commit();
    List<Entry> entries = getApi().getEntries().reference(refMode.transform(branch)).get().getEntries();
    assertThat(entries).isNotNull().hasSize(4);
    entries = getApi().getEntries().reference(refMode.transform(branch)).get().getEntries();
    assertThat(entries).isNotNull().hasSize(4);
    entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.namespace.startsWith('a.b')").get().getEntries();
    assertThat(entries).hasSize(2);
    entries.forEach(e -> assertThat(e.getName().getNamespace().name()).startsWith("a.b"));
    entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.namespace.startsWith('a')").get().getEntries();
    assertThat(entries).hasSize(4);
    entries.forEach(e -> assertThat(e.getName().getNamespace().name()).startsWith("a"));
    entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.namespace.startsWith('a.b.c.firstTable')").get().getEntries();
    assertThat(entries).isEmpty();
    entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.namespace.startsWith('a.fourthTable')").get().getEntries();
    assertThat(entries).isEmpty();
    getApi().deleteBranch().branchName(branch.getName()).hash(getApi().getReference().refName(branch.getName()).get().getHash()).delete();
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Entry(org.projectnessie.model.EntriesResponse.Entry) Branch(org.projectnessie.model.Branch) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with Entry

use of org.projectnessie.model.EntriesResponse.Entry in project nessie by projectnessie.

the class AbstractTestBasicOperations method testAdmin.

@Test
@TestSecurity(user = "admin_user", roles = { "admin", "user" })
void testAdmin() throws BaseNessieClientServerException {
    getCatalog("testx");
    Branch branch = (Branch) api.getReference().refName("testx").get();
    List<Entry> tables = api.getEntries().refName("testx").get().getEntries();
    Assertions.assertTrue(tables.isEmpty());
    ContentKey key = ContentKey.of("x", "x");
    tryEndpointPass(() -> api.commitMultipleOperations().branch(branch).operation(Put.of(key, IcebergTable.of("foo", 42, 42, 42, 42, "cid-foo"))).commitMeta(CommitMeta.fromMessage("empty message")).commit());
    Assertions.assertTrue(api.getContent().refName("testx").key(key).get().get(key).unwrap(IcebergTable.class).isPresent());
    Branch master = (Branch) api.getReference().refName("testx").get();
    Branch test = Branch.of("testy", master.getHash());
    tryEndpointPass(() -> api.createReference().sourceRefName(master.getName()).reference(test).create());
    Branch test2 = (Branch) api.getReference().refName("testy").get();
    tryEndpointPass(() -> api.deleteBranch().branch(test2).delete());
    tryEndpointPass(() -> api.commitMultipleOperations().branch(master).operation(Delete.of(key)).commitMeta(CommitMeta.fromMessage("")).commit());
    assertThat(api.getContent().refName("testx").key(key).get()).isEmpty();
    tryEndpointPass(() -> {
        Branch b = (Branch) api.getReference().refName(branch.getName()).get();
        // Note: the initial version-store implementations just committed this operation, but it
        // should actually fail, because the operations of the 1st commit above and this commit
        // have conflicts.
        api.commitMultipleOperations().branch(b).operation(Put.of(key, IcebergTable.of("bar", 42, 42, 42, 42, "cid-bar"))).commitMeta(CommitMeta.fromMessage("")).commit();
    });
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Entry(org.projectnessie.model.EntriesResponse.Entry) Branch(org.projectnessie.model.Branch) TestSecurity(io.quarkus.test.security.TestSecurity) Test(org.junit.jupiter.api.Test)

Example 5 with Entry

use of org.projectnessie.model.EntriesResponse.Entry 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)

Aggregations

Branch (org.projectnessie.model.Branch)10 Entry (org.projectnessie.model.EntriesResponse.Entry)10 ContentKey (org.projectnessie.model.ContentKey)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 CommitMeta (org.projectnessie.model.CommitMeta)6 IcebergTable (org.projectnessie.model.IcebergTable)6 Test (org.junit.jupiter.api.Test)5 Namespace (org.projectnessie.model.Namespace)5 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 LogResponse (org.projectnessie.model.LogResponse)4 LogEntry (org.projectnessie.model.LogResponse.LogEntry)4 Put (org.projectnessie.model.Operation.Put)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 CommitMultipleOperationsBuilder (org.projectnessie.client.api.CommitMultipleOperationsBuilder)3 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)3 IcebergView (org.projectnessie.model.IcebergView)3 Arrays (java.util.Arrays)2 Collections.singletonList (java.util.Collections.singletonList)2