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();
}
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();
}
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();
}
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();
});
}
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);
}
Aggregations