<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.apache.jackrabbit.oak.core;

import java.util.Iterator;
import java.util.Random;

import javax.security.auth.Subject;

import org.apache.jackrabbit.mk.api.MicroKernel;
import org.apache.jackrabbit.mk.core.MicroKernelImpl;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.Rebase;
import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
import org.apache.jackrabbit.oak.security.authorization.AccessControlProviderImpl;
import org.apache.jackrabbit.oak.spi.query.CompositeQueryIndexProvider;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.AddNode;
import static org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.CopyNode;
import static org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.MoveNode;
import static org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.RemoveNode;
import static org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.RemoveProperty;
import static org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.Save;
import static org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.SetProperty;
import static org.junit.Assert.assertEquals;

/**
 * Fuzz test running random sequences of operations on {@link Tree}.
 * Run with -DKernelRootFuzzIT-seed=42 to set a specific seed (i.e. 42);
 */
public class RootImplFuzzIT {

    static final Logger log = LoggerFactory.getLogger(RootImplFuzzIT.class);

    private static final int OP_COUNT = 5000;

    private static final int SEED = Integer.getInteger(
            RootImplFuzzIT.class.getSimpleName() + "-seed",
            new Random().nextInt());

    private static final Random random = new Random(SEED);

    private KernelNodeStore store1;
    private RootImpl root1;

    private KernelNodeStore store2;
    private RootImpl root2;

    private int counter;

    @Before
    public void setup() {
        counter = 0;

        MicroKernel mk1 = new MicroKernelImpl("./target/mk1/" + random.nextInt());
        store1 = new KernelNodeStore(mk1);
        mk1.commit("", "+\"/root\":{}", mk1.getHeadRevision(), "");
        root1 = new RootImpl(store1, null, new Subject(),
                new AccessControlProviderImpl(), new CompositeQueryIndexProvider());

        MicroKernel mk2 = new MicroKernelImpl("./target/mk2/" + random.nextInt());
        store2 = new KernelNodeStore(mk2);
        mk2.commit("", "+\"/root\":{}", mk2.getHeadRevision(), "");
        root2 = new RootImpl(store2, null, new Subject(),
                new AccessControlProviderImpl(), new CompositeQueryIndexProvider());
    }

    @Test
    public void fuzzTest() throws Exception {<commit_msg>simplify setup of RootImplFuzzIT<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.apache.jackrabbit.oak.core;

import java.util.Iterator;
import java.util.Random;

import org.apache.jackrabbit.mk.api.MicroKernel;
import org.apache.jackrabbit.mk.core.MicroKernelImpl;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.Rebase;
import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.AddNode;
import static org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.CopyNode;
import static org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.MoveNode;
import static org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.RemoveNode;
import static org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.RemoveProperty;
import static org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.Save;
import static org.apache.jackrabbit.oak.core.RootImplFuzzIT.Operation.SetProperty;
import static org.junit.Assert.assertEquals;

/**
 * Fuzz test running random sequences of operations on {@link Tree}.
 * Run with -DKernelRootFuzzIT-seed=42 to set a specific seed (i.e. 42);
 */
public class RootImplFuzzIT {

    static final Logger log = LoggerFactory.getLogger(RootImplFuzzIT.class);

    private static final int OP_COUNT = 5000;

    private static final int SEED = Integer.getInteger(
            RootImplFuzzIT.class.getSimpleName() + "-seed",
            new Random().nextInt());

    private static final Random random = new Random(SEED);

    private KernelNodeStore store1;
    private RootImpl root1;

    private KernelNodeStore store2;
    private RootImpl root2;

    private int counter;

    @Before
    public void setup() {
        counter = 0;

        MicroKernel mk1 = new MicroKernelImpl("./target/mk1/" + random.nextInt());
        store1 = new KernelNodeStore(mk1);
        mk1.commit("", "+\"/root\":{}", mk1.getHeadRevision(), "");
        root1 = new RootImpl(store1);

        MicroKernel mk2 = new MicroKernelImpl("./target/mk2/" + random.nextInt());
        store2 = new KernelNodeStore(mk2);
        mk2.commit("", "+\"/root\":{}", mk2.getHeadRevision(), "");
        root2 = new RootImpl(store2);
    }

    @Test
    public void fuzzTest() throws Exception {
{'fraction_non_alphanumeric': 0.10232956981563528, 'fraction_numerical': 0.010004287551807918, 'mean_word_length': 4.03453237410072, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6543044', 'n_tokens_mistral': 2091, 'n_tokens_neox': 2007, 'n_words': 565}