Search in sources :

Example 1 with NessieApiV1

use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.

the class BaseIcebergTest method beforeEach.

@BeforeEach
public void beforeEach(@NessieUri URI x) throws IOException {
    uri = x.toString();
    this.api = HttpClientBuilder.builder().withUri(uri).build(NessieApiV1.class);
    resetData();
    try {
        api.createReference().reference(Branch.of(branch, null)).create();
    } catch (Exception e) {
    // ignore, already created. Can't run this in BeforeAll as quarkus hasn't disabled auth
    }
    hadoopConfig = new Configuration();
    catalog = initCatalog(branch);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) NessieConflictException(org.projectnessie.error.NessieConflictException) IOException(java.io.IOException) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) NessieApiV1(org.projectnessie.client.api.NessieApiV1) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with NessieApiV1

use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.

the class TestNessieApiHolder method oldVersionServer.

@Test
void oldVersionServer() throws Throwable {
    ExtensionValuesStore valuesStore = new ExtensionValuesStore(null);
    try {
        Store store = new NamespaceAwareStore(valuesStore, Util.NAMESPACE);
        ExtensionContext ctx = mock(ExtensionContext.class);
        when(ctx.getRoot()).thenReturn(ctx);
        when(ctx.getStore(any(Namespace.class))).thenReturn(store);
        OldNessieApiHolder apiHolder = new OldNessieApiHolder(ctx, new ClientKey(Version.parseVersion("0.19.0"), "org.projectnessie.client.http.HttpClientBuilder", NessieApiV1.class, Collections.singletonMap("nessie.uri", "http://127.42.42.42:19120")));
        try {
            assertThat(apiHolder).satisfies(api -> assertThat(api.getApiInstance().getClass()).matches(Proxy::isProxyClass)).extracting(OldNessieApiHolder::getTranslatingApiInstance).extracting(TranslatingVersionNessieApi::getOldVersionApiInstance).extracting(Object::getClass).extracting(Class::getClassLoader).isNotSameAs(Thread.currentThread().getContextClassLoader());
        } finally {
            apiHolder.close();
        }
    } finally {
        valuesStore.closeAllStoredCloseableValues();
    }
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Proxy(java.lang.reflect.Proxy) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mockito.when(org.mockito.Mockito.when) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Store(org.junit.jupiter.api.extension.ExtensionContext.Store) NessieApiV1(org.projectnessie.client.api.NessieApiV1) Test(org.junit.jupiter.api.Test) NamespaceAwareStore(org.junit.jupiter.engine.execution.NamespaceAwareStore) ExtensionValuesStore(org.junit.jupiter.engine.execution.ExtensionValuesStore) Collections(java.util.Collections) Namespace(org.junit.jupiter.api.extension.ExtensionContext.Namespace) Mockito.mock(org.mockito.Mockito.mock) Version(org.projectnessie.tools.compatibility.api.Version) ExtensionValuesStore(org.junit.jupiter.engine.execution.ExtensionValuesStore) Proxy(java.lang.reflect.Proxy) NamespaceAwareStore(org.junit.jupiter.engine.execution.NamespaceAwareStore) Store(org.junit.jupiter.api.extension.ExtensionContext.Store) NamespaceAwareStore(org.junit.jupiter.engine.execution.NamespaceAwareStore) ExtensionValuesStore(org.junit.jupiter.engine.execution.ExtensionValuesStore) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Namespace(org.junit.jupiter.api.extension.ExtensionContext.Namespace) NessieApiV1(org.projectnessie.client.api.NessieApiV1) Test(org.junit.jupiter.api.Test)

Example 3 with NessieApiV1

use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.

the class GenerateContent method execute.

@Override
public void execute() throws BaseNessieClientServerException {
    if (runtimeDuration != null) {
        if (runtimeDuration.isZero() || runtimeDuration.isNegative()) {
            throw new ParameterException(spec.commandLine(), "Duration must be absent to greater than zero.");
        }
    }
    Duration perCommitDuration = Optional.ofNullable(runtimeDuration).orElse(Duration.ZERO).dividedBy(numCommits);
    ThreadLocalRandom random = ThreadLocalRandom.current();
    String runStartTime = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss").format(LocalDateTime.now());
    List<ContentKey> tableNames = IntStream.range(0, numTables).mapToObj(i -> ContentKey.of(String.format("create-contents-%s", runStartTime), "contents", Integer.toString(i))).collect(Collectors.toList());
    try (NessieApiV1 api = createNessieApiInstance()) {
        Branch defaultBranch;
        if (defaultBranchName == null) {
            // Use the server's default branch.
            defaultBranch = api.getDefaultBranch();
        } else {
            // Use the specified default branch.
            try {
                defaultBranch = (Branch) api.getReference().refName(defaultBranchName).get();
            } catch (NessieReferenceNotFoundException e) {
                // Create branch if it does not exist.
                defaultBranch = api.getDefaultBranch();
                defaultBranch = (Branch) api.createReference().reference(Branch.of(defaultBranchName, defaultBranch.getHash())).sourceRefName(defaultBranch.getName()).create();
            }
        }
        List<String> branches = new ArrayList<>();
        branches.add(defaultBranch.getName());
        while (branches.size() < branchCount) {
            // Create a new branch
            String newBranchName = "branch-" + runStartTime + "_" + (branches.size() - 1);
            Branch branch = Branch.of(newBranchName, defaultBranch.getHash());
            spec.commandLine().getOut().printf("Creating branch '%s' from '%s' at %s%n", branch.getName(), defaultBranch.getName(), branch.getHash());
            api.createReference().reference(branch).sourceRefName(defaultBranch.getName()).create();
            branches.add(newBranchName);
        }
        spec.commandLine().getOut().printf("Starting contents generation, %d commits...%n", numCommits);
        for (int i = 0; i < numCommits; i++) {
            // Choose a random branch to commit to
            String branchName = branches.get(random.nextInt(branches.size()));
            Branch commitToBranch = (Branch) api.getReference().refName(branchName).get();
            ContentKey tableName = tableNames.get(random.nextInt(tableNames.size()));
            Content tableContents = api.getContent().refName(branchName).key(tableName).get().get(tableName);
            Content newContents = createContents(tableContents, random);
            spec.commandLine().getOut().printf("Committing content-key '%s' to branch '%s' at %s%n", tableName, commitToBranch.getName(), commitToBranch.getHash());
            CommitMultipleOperationsBuilder commit = api.commitMultipleOperations().branch(commitToBranch).commitMeta(CommitMeta.builder().message(String.format("%s table %s on %s, commit #%d of %d", tableContents != null ? "Update" : "Create", tableName, branchName, i, numCommits)).author(System.getProperty("user.name")).authorTime(Instant.now()).build());
            if (newContents instanceof IcebergTable || newContents instanceof IcebergView) {
                commit.operation(Put.of(tableName, newContents, tableContents));
            } else {
                commit.operation(Put.of(tableName, newContents));
            }
            Branch newHead = commit.commit();
            if (random.nextDouble() < newTagProbability) {
                Tag tag = Tag.of("new-tag-" + random.nextLong(), newHead.getHash());
                spec.commandLine().getOut().printf("Creating tag '%s' from '%s' at %s%n", tag.getName(), branchName, tag.getHash());
                api.createReference().reference(tag).sourceRefName(branchName).create();
            }
            try {
                TimeUnit.NANOSECONDS.sleep(perCommitDuration.toNanos());
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                break;
            }
        }
    }
    spec.commandLine().getOut().printf("Done creating contents.%n");
}
Also used : IntStream(java.util.stream.IntStream) ImmutableIcebergView(org.projectnessie.model.ImmutableIcebergView) Put(org.projectnessie.model.Operation.Put) LocalDateTime(java.time.LocalDateTime) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ParameterException(picocli.CommandLine.ParameterException) Spec(picocli.CommandLine.Spec) ArrayList(java.util.ArrayList) Duration(java.time.Duration) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) Command(picocli.CommandLine.Command) Branch(org.projectnessie.model.Branch) ImmutableDeltaLakeTable(org.projectnessie.model.ImmutableDeltaLakeTable) Min(javax.validation.constraints.Min) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) NessieApiV1(org.projectnessie.client.api.NessieApiV1) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ImmutableIcebergTable(org.projectnessie.model.ImmutableIcebergTable) Option(picocli.CommandLine.Option) IcebergView(org.projectnessie.model.IcebergView) IcebergTable(org.projectnessie.model.IcebergTable) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) Tag(org.projectnessie.model.Tag) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) CommandSpec(picocli.CommandLine.Model.CommandSpec) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) ArrayList(java.util.ArrayList) Duration(java.time.Duration) ImmutableIcebergView(org.projectnessie.model.ImmutableIcebergView) IcebergView(org.projectnessie.model.IcebergView) ContentKey(org.projectnessie.model.ContentKey) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ImmutableIcebergTable(org.projectnessie.model.ImmutableIcebergTable) IcebergTable(org.projectnessie.model.IcebergTable) ParameterException(picocli.CommandLine.ParameterException) Tag(org.projectnessie.model.Tag) NessieApiV1(org.projectnessie.client.api.NessieApiV1)

Example 4 with NessieApiV1

use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.

the class ReadContent method execute.

@Override
public void execute() throws NessieNotFoundException {
    try (NessieApiV1 api = createNessieApiInstance()) {
        ContentKey contentKey = ContentKey.of(key);
        spec.commandLine().getOut().printf("Reading content for key '%s'\n\n", contentKey);
        Map<ContentKey, Content> contentMap = api.getContent().refName(ref).key(contentKey).get();
        for (Map.Entry<ContentKey, Content> entry : contentMap.entrySet()) {
            spec.commandLine().getOut().printf("Key: %s\n", entry.getKey());
            if (isVerbose()) {
                List<String> key = entry.getKey().getElements();
                for (int i = 0; i < key.size(); i++) {
                    spec.commandLine().getOut().printf("  key[%d]: %s\n", i, key.get(i));
                }
            }
            spec.commandLine().getOut().printf("Value: %s\n", entry.getValue());
        }
        spec.commandLine().getOut().printf("\nDone reading content for key '%s'\n\n", contentKey);
    }
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Content(org.projectnessie.model.Content) Map(java.util.Map) NessieApiV1(org.projectnessie.client.api.NessieApiV1)

Example 5 with NessieApiV1

use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.

the class ReadReferences method execute.

@Override
public void execute() {
    try (NessieApiV1 api = createNessieApiInstance()) {
        spec.commandLine().getOut().printf("Reading all references\n\n");
        List<Reference> references = api.getAllReferences().get().getReferences();
        references.forEach(reference -> spec.commandLine().getOut().printf(reference + "\n"));
        spec.commandLine().getOut().printf("\nDone reading all references\n\n");
    }
}
Also used : Reference(org.projectnessie.model.Reference) NessieApiV1(org.projectnessie.client.api.NessieApiV1)

Aggregations

NessieApiV1 (org.projectnessie.client.api.NessieApiV1)25 Test (org.junit.jupiter.api.Test)11 TestServer (org.projectnessie.client.util.TestServer)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Instant (java.time.Instant)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Stream (java.util.stream.Stream)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 InstanceOfAssertFactories (org.assertj.core.api.InstanceOfAssertFactories)2 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 Arguments (org.junit.jupiter.params.provider.Arguments)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 FetchOption (org.projectnessie.api.params.FetchOption)2 HttpClient (org.projectnessie.client.http.HttpClient)2 HttpApiV1 (org.projectnessie.client.http.v1api.HttpApiV1)2 NessieInternalServerException (org.projectnessie.client.rest.NessieInternalServerException)2