All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.projectnessie.versioned.impl.AbstractTieredStoreFixture Maven / Gradle / Ivy
/*
* Copyright (C) 2020 Dremio
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.projectnessie.versioned.impl;
import static org.mockito.Mockito.spy;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import org.projectnessie.versioned.BranchName;
import org.projectnessie.versioned.Diff;
import org.projectnessie.versioned.Hash;
import org.projectnessie.versioned.Key;
import org.projectnessie.versioned.NamedRef;
import org.projectnessie.versioned.Operation;
import org.projectnessie.versioned.Ref;
import org.projectnessie.versioned.ReferenceAlreadyExistsException;
import org.projectnessie.versioned.ReferenceConflictException;
import org.projectnessie.versioned.ReferenceNotFoundException;
import org.projectnessie.versioned.StoreWorker;
import org.projectnessie.versioned.StringSerializer;
import org.projectnessie.versioned.VersionStore;
import org.projectnessie.versioned.WithHash;
import org.projectnessie.versioned.WithType;
import org.projectnessie.versioned.store.Store;
public abstract class AbstractTieredStoreFixture
implements VersionStore, AutoCloseable {
protected static final StoreWorker WORKER =
StoreWorker.of(StringSerializer.getInstance(), StringSerializer.getInstance());
private final C config;
private final S store;
private final VersionStore versionStore;
/** Create a new fixture. */
protected AbstractTieredStoreFixture(C config) {
this.config = config;
S storeImpl = createStoreImpl();
storeImpl.start();
store = spy(storeImpl);
VersionStore versionStoreImpl =
new TieredVersionStore<>(
WORKER,
store,
ImmutableTieredVersionStoreConfig.builder()
.enableTracing(true)
.waitOnCollapse(true)
.build());
versionStore = spy(versionStoreImpl);
}
public C getConfig() {
return config;
}
public abstract S createStoreImpl();
public S getStore() {
return store;
}
@Override
@Nonnull
public Hash toHash(@Nonnull NamedRef ref) throws ReferenceNotFoundException {
return versionStore.toHash(ref);
}
@Override
public Hash commit(
@Nonnull BranchName branch,
@Nonnull Optional expectedHash,
@Nonnull String metadata,
@Nonnull List> operations)
throws ReferenceNotFoundException, ReferenceConflictException {
return versionStore.commit(branch, expectedHash, metadata, operations);
}
@Override
public void transplant(
BranchName targetBranch, Optional expectedHash, List sequenceToTransplant)
throws ReferenceNotFoundException, ReferenceConflictException {
versionStore.transplant(targetBranch, expectedHash, sequenceToTransplant);
}
@Override
public void merge(Hash fromHash, BranchName toBranch, Optional expectedHash)
throws ReferenceNotFoundException, ReferenceConflictException {
versionStore.merge(fromHash, toBranch, expectedHash);
}
@Override
public void assign(NamedRef ref, Optional expectedHash, Hash targetHash)
throws ReferenceNotFoundException, ReferenceConflictException {
versionStore.assign(ref, expectedHash, targetHash);
}
@Override
public Hash create(NamedRef ref, Optional targetHash)
throws ReferenceNotFoundException, ReferenceAlreadyExistsException {
return versionStore.create(ref, targetHash);
}
@Override
public void delete(NamedRef ref, Optional hash)
throws ReferenceNotFoundException, ReferenceConflictException {
versionStore.delete(ref, hash);
}
@Override
public Stream> getNamedRefs() {
return versionStore.getNamedRefs();
}
@Override
public Stream> getCommits(Ref ref) throws ReferenceNotFoundException {
return versionStore.getCommits(ref);
}
@Override
public Stream> getKeys(Ref ref)
throws ReferenceNotFoundException {
return versionStore.getKeys(ref);
}
@Override
public String getValue(Ref ref, Key key) throws ReferenceNotFoundException {
return versionStore.getValue(ref, key);
}
@Override
public List> getValues(Ref ref, List key)
throws ReferenceNotFoundException {
return versionStore.getValues(ref, key);
}
@Override
public WithHash[ toRef(@Nonnull String refOfUnknownType) throws ReferenceNotFoundException {
return versionStore.toRef(refOfUnknownType);
}
@Override
public Stream]> getDiffs(Ref from, Ref to) throws ReferenceNotFoundException {
return versionStore.getDiffs(from, to);
}
@Override
public Collector collectGarbage() {
return versionStore.collectGarbage();
}
}