use of org.projectnessie.model.Branch 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.Branch in project nessie by projectnessie.
the class AbstractRestInvalidRefs method testValidHashesOnValidNamedRefs.
@Test
public void testValidHashesOnValidNamedRefs() throws BaseNessieClientServerException {
Branch branch = createBranch("testValidHashesOnValidNamedRefs");
int commits = 10;
String currentHash = branch.getHash();
createCommits(branch, 1, commits, currentHash);
LogResponse entireLog = getApi().getCommitLog().refName(branch.getName()).get();
assertThat(entireLog).isNotNull();
assertThat(entireLog.getLogEntries()).hasSize(commits);
EntriesResponse allEntries = getApi().getEntries().refName(branch.getName()).get();
assertThat(allEntries).isNotNull();
assertThat(allEntries.getEntries()).hasSize(commits);
List<ContentKey> keys = new ArrayList<>();
IntStream.range(0, commits).forEach(i -> keys.add(ContentKey.of("table" + i)));
// TODO: check where hashOnRef is set
Map<ContentKey, Content> allContent = getApi().getContent().keys(keys).refName(branch.getName()).get();
for (int i = 0; i < commits; i++) {
String hash = entireLog.getLogEntries().get(i).getCommitMeta().getHash();
LogResponse log = getApi().getCommitLog().refName(branch.getName()).hashOnRef(hash).get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(commits - i);
assertThat(ImmutableList.copyOf(entireLog.getLogEntries()).subList(i, commits)).containsExactlyElementsOf(log.getLogEntries());
EntriesResponse entries = getApi().getEntries().refName(branch.getName()).hashOnRef(hash).get();
assertThat(entries).isNotNull();
assertThat(entries.getEntries()).hasSize(commits - i);
int idx = commits - 1 - i;
ContentKey key = ContentKey.of("table" + idx);
Content c = getApi().getContent().key(key).refName(branch.getName()).hashOnRef(hash).get().get(key);
assertThat(c).isNotNull().isEqualTo(allContent.get(key));
}
}
use of org.projectnessie.model.Branch in project nessie by projectnessie.
the class AbstractRestGCTest method testSingleRefDropRefAfterCutoff.
@Test
public void testSingleRefDropRefAfterCutoff() throws BaseNessieClientServerException {
// ------ Time ---- | ---------- branch1 ------------------|
// t0 | create branch
// t1 | TABLE_ONE : 42
// t2 | TABLE_TWO : 42 (expired)
// t3 | TABLE_TWO : 43
// t4 | ------- cut off time ----------------|
// t5 | delete branch
String prefix = "singleRefDropRefAfterCutoff";
IdentifiedResult expectedResult = new IdentifiedResult();
Branch branch1 = createBranch(prefix);
// one commit for TABLE_ONE on branch1
CommitOutput table1 = commitSingleOp(prefix, branch1, branch1.getHash(), 42, CID_ONE, TABLE_ONE, METADATA_ONE, null, null);
// two commits for TABLE_TWO on branch1
CommitOutput table2 = commitSingleOp(prefix, branch1, branch1.getHash(), 42, CID_TWO, TABLE_TWO, METADATA_ONE, null, null);
// after cutoff time.
fillExpectedContents(Branch.of(branch1.getName(), table2.hash), 1, expectedResult);
// one commit for TABLE_TWO on branch1
table2 = commitSingleOp(prefix, branch1, table2.hash, 43, CID_TWO, TABLE_TWO, METADATA_TWO, table2.content, null);
final Instant cutoffTime = Instant.now();
// delete branch before cutoff time
deleteBranch(branch1.getName(), table2.hash);
performGc(cutoffTime, null, expectedResult, Collections.singletonList(branch1.getName()), true, null);
}
use of org.projectnessie.model.Branch in project nessie by projectnessie.
the class AbstractRestGCTest method testSingleRefDeadRefCutoff.
@Test
public void testSingleRefDeadRefCutoff() throws BaseNessieClientServerException {
// ------ Time ---- | ---------- branch1 ------------------|
// t0 | create branch
// t1 | TABLE_ONE : 42
// t4 | ------- default cut off time --------|
// t2 | TABLE_TWO : 42 (expired)
// t3 | TABLE_TWO : 43 (expired)
// t3 | TABLE_TWO : 44
// t4 | ------- dead ref cut off time -------|
// t5 | delete branch
String prefix = "singleRefDeadRefCutoff";
IdentifiedResult expectedResult = new IdentifiedResult();
Branch branch1 = createBranch(prefix);
// one commit for TABLE_ONE on branch1
CommitOutput table1 = commitSingleOp(prefix, branch1, branch1.getHash(), 42, CID_ONE, TABLE_ONE, METADATA_ONE, null, null);
final Instant cutoffTime = Instant.now();
// two commits for TABLE_TWO on branch1
CommitOutput table2 = commitSingleOp(prefix, branch1, branch1.getHash(), 42, CID_TWO, TABLE_TWO, METADATA_ONE, null, null);
table2 = commitSingleOp(prefix, branch1, table2.hash, 43, CID_TWO, TABLE_TWO, METADATA_TWO, table2.content, null);
// last two commits are expected to be expired as it is not the commit head
// and commit is before dead ref cutoff time.
fillExpectedContents(Branch.of(branch1.getName(), table2.hash), 2, expectedResult);
table2 = commitSingleOp(prefix, branch1, table2.hash, 44, CID_TWO, TABLE_TWO, METADATA_THREE, table2.content, null);
final Instant deadRefCutoffTime = Instant.now();
// delete branch before cutoff time
deleteBranch(branch1.getName(), table2.hash);
performGc(cutoffTime, null, expectedResult, Collections.singletonList(branch1.getName()), true, deadRefCutoffTime);
}
use of org.projectnessie.model.Branch in project nessie by projectnessie.
the class AbstractRestGCTest method testMultiRefAssignAndDropRef.
@Test
public void testMultiRefAssignAndDropRef() throws BaseNessieClientServerException {
// ------ Time ---- | --- branch1 -------------| ---- branch2 ----------- |
// t0 | create branch | |
// t1 | | create branch |
// t2 | TABLE_ONE : 42 (expired) | |
// t3 | | TABLE_TWO : 42 (expired) |
// t4 | TABLE_ONE : 43 | |
// t5 | | TABLE_TWO : 43 |
// t6 |-- cut off time -------- |-- cut off time -------- |
// t7 | TABLE_ONE : 44 | |
// t8 | | TABLE_TWO : 44 |
// t9 | | assign main to this branch |
// t10 | delete branch | |
String prefix = "multiRefAssignAndDropRef";
IdentifiedResult expectedResult = new IdentifiedResult();
// 'before' is same as main branch
Branch before = createBranch(prefix + "_0");
Branch branch1 = createBranch(prefix + "_1");
Branch branch2 = createBranch(prefix + "_2");
// commit for TABLE_ONE on branch1
CommitOutput table1 = commitSingleOp(prefix, branch1, branch1.getHash(), 42, CID_ONE, TABLE_ONE, METADATA_ONE, null, null);
// expect this commit to be expired as it is before cutoff time and not the head commit
fillExpectedContents(Branch.of(branch1.getName(), table1.hash), 1, expectedResult);
// commit for TABLE_TWO on branch2
CommitOutput table2 = commitSingleOp(prefix, branch2, branch2.getHash(), 42, CID_TWO, TABLE_TWO, METADATA_ONE, null, null);
// expect this commit to be expired as it is before cutoff time and not the head commit
fillExpectedContents(Branch.of(branch2.getName(), table2.hash), 1, expectedResult);
table1 = commitSingleOp(prefix, branch1, table1.hash, 43, CID_ONE, TABLE_ONE, METADATA_TWO, table1.content, null);
table2 = commitSingleOp(prefix, branch2, table2.hash, 43, CID_TWO, TABLE_TWO, METADATA_TWO, table2.content, null);
final Instant cutoffTime = Instant.now();
// commits for TABLE_ONE on branch 1
table1 = commitSingleOp(prefix, branch1, table1.hash, 44, CID_ONE, TABLE_ONE, METADATA_THREE, table1.content, null);
// commits for TABLE_TWO on branch2
table2 = commitSingleOp(prefix, branch2, table2.hash, 44, CID_TWO, TABLE_TWO, METADATA_THREE, table2.content, null);
// assign main to branch2 should not affect as it is performed after cutoff.
getApi().assignBranch().branch(Branch.of(branch2.getName(), table2.hash)).assignTo(before).assign();
// drop ref branch1 should not affect as it is performed after cutoff timestamp.
deleteBranch(branch1.getName(), table1.hash);
performGc(cutoffTime, null, expectedResult, Arrays.asList(branch1.getName(), branch2.getName()), true, null);
}
Aggregations