/*
 * Copyright (C) 2016-2023 Hedera Hashgraph, LLC
 *
 * 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 com.swirlds.virtual.merkle.reconnect;

import com.swirlds.config.api.Configuration;
import com.swirlds.jasperdb.config.JasperDbConfig;
import com.swirlds.jasperdb.files.hashmap.HalfDiskVirtualKeySet;
import com.swirlds.test.framework.config.TestConfigBuilder;
import com.swirlds.virtual.merkle.TestKey;
import com.swirlds.virtual.merkle.TestKeySerializer;
import com.swirlds.virtual.merkle.TestValue;
import com.swirlds.virtualmap.datasource.VirtualDataSource;
import com.swirlds.virtualmap.datasource.VirtualKeySet;

public class BreakableDataSourceJPDB extends BreakableDataSource {

    public BreakableDataSourceJPDB(final BrokenBuilder builder, final VirtualDataSource<TestKey, TestValue> delegate) {
        super(builder, delegate);
    }

    @Override
    public VirtualKeySet<TestKey> buildKeySet() {
        final Configuration configuration = new TestConfigBuilder()
                .withValue("jasperDb.keySetHalfDiskHashMapSize", "10000")
                .withValue("jasperDb.keySetHalfDiskHashMapBuffer", "1000")
                .withValue("jasperDb.keySetBloomFilterSizeInBytes", "16777216")
                .getOrCreateConfig();

        return new HalfDiskVirtualKeySet<>(new TestKeySerializer(), configuration.getConfigData(JasperDbConfig.class));
    }
}
