<commit_before>/**
 * Copyright (c) 2002-2012 "Neo Technology,"
 * Network Engine for Objects in Lund AB [http://neotechnology.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.neo4j.kernel.impl.core;

import static org.junit.Assert.assertEquals;

import java.io.File;

import org.junit.BeforeClass;
import org.junit.Test;
import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.kernel.Config;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.neo4j.kernel.impl.AbstractNeo4jTestCase;
import org.neo4j.kernel.impl.core.NodeManager.CacheType;

public class TestCacheTypes extends AbstractNeo4jTestCase
{
    private static final String PATH = getStorePath( "cache-db" );

    @BeforeClass
    public static void clear()
    {
        deleteFileOrDirectory( new File( PATH ) );
    }
    
    private EmbeddedGraphDatabase newDb( String cacheType )
    {
        return new EmbeddedGraphDatabase( PATH, MapUtil.stringMap( Config.CACHE_TYPE, cacheType ) );
    }

    @Test
    public void testDefaultCache()
    {
        EmbeddedGraphDatabase db = newDb( null );
        try
        {
            assertEquals( CacheType.array, db.getNodeManager().getCacheType() );
        }
        finally
        {
            db.shutdown();
        }
    }

    @Test
    public void testWeakRefCache()
    {
        EmbeddedGraphDatabase db = newDb( "weak" );
        assertEquals( CacheType.weak, db.getNodeManager().getCacheType() );
        db.shutdown();
    }

    @Test
    public void testSoftRefCache()
    {
        EmbeddedGraphDatabase db = newDb( "soft" );
        assertEquals( CacheType.soft, db.getNodeManager().getCacheType() );
        db.shutdown();
    }

    @Test
    public void testNoCache()
    {
        EmbeddedGraphDatabase db = newDb( "none" );
        assertEquals( CacheType.none, db.getNodeManager().getCacheType() );
        db.shutdown();
    }

    @Test
    public void testStrongCache()
    {
        EmbeddedGraphDatabase db = newDb( "strong" );
        assertEquals( CacheType.strong, db.getNodeManager().getCacheType() );
        db.shutdown();
    }

    @Test
    public void testArrayCache()
    {
        EmbeddedGraphDatabase db = newDb( "array" );
        assertEquals( CacheType.array, db.getNodeManager().getCacheType() );
        db.shutdown();
    }
    
    @Test
    public void testInvalidCache()
    {
        // invalid cache type should use default and print a warning
        EmbeddedGraphDatabase db = newDb( "whatever" );
        assertEquals( CacheType.array, db.getNodeManager().getCacheType() );
        db.shutdown();
    }
}
<commit_msg>Soft is default<commit_after>/**
 * Copyright (c) 2002-2012 "Neo Technology,"
 * Network Engine for Objects in Lund AB [http://neotechnology.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.neo4j.kernel.impl.core;

import static org.junit.Assert.assertEquals;

import java.io.File;

import org.junit.BeforeClass;
import org.junit.Test;
import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.kernel.Config;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.neo4j.kernel.impl.AbstractNeo4jTestCase;
import org.neo4j.kernel.impl.core.NodeManager.CacheType;

public class TestCacheTypes extends AbstractNeo4jTestCase
{
    private static final String PATH = getStorePath( "cache-db" );

    @BeforeClass
    public static void clear()
    {
        deleteFileOrDirectory( new File( PATH ) );
    }
    
    private EmbeddedGraphDatabase newDb( String cacheType )
    {
        return new EmbeddedGraphDatabase( PATH, MapUtil.stringMap( Config.CACHE_TYPE, cacheType ) );
    }

    @Test
    public void testDefaultCache()
    {
        EmbeddedGraphDatabase db = newDb( null );
        try
        {
            assertEquals( CacheType.soft, db.getNodeManager().getCacheType() );
        }
        finally
        {
            db.shutdown();
        }
    }

    @Test
    public void testWeakRefCache()
    {
        EmbeddedGraphDatabase db = newDb( "weak" );
        assertEquals( CacheType.weak, db.getNodeManager().getCacheType() );
        db.shutdown();
    }

    @Test
    public void testSoftRefCache()
    {
        EmbeddedGraphDatabase db = newDb( "soft" );
        assertEquals( CacheType.soft, db.getNodeManager().getCacheType() );
        db.shutdown();
    }

    @Test
    public void testNoCache()
    {
        EmbeddedGraphDatabase db = newDb( "none" );
        assertEquals( CacheType.none, db.getNodeManager().getCacheType() );
        db.shutdown();
    }

    @Test
    public void testStrongCache()
    {
        EmbeddedGraphDatabase db = newDb( "strong" );
        assertEquals( CacheType.strong, db.getNodeManager().getCacheType() );
        db.shutdown();
    }

    @Test
    public void testArrayCache()
    {
        EmbeddedGraphDatabase db = newDb( "array" );
        assertEquals( CacheType.array, db.getNodeManager().getCacheType() );
        db.shutdown();
    }
    
    @Test
    public void testInvalidCache()
    {
        // invalid cache type should use default and print a warning
        EmbeddedGraphDatabase db = newDb( "whatever" );
        assertEquals( CacheType.soft, db.getNodeManager().getCacheType() );
        db.shutdown();
    }
}

{'fraction_non_alphanumeric': 0.09910741766697445, 'fraction_numerical': 0.005847953216374269, 'mean_word_length': 2.7850902737332555, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4558101', 'n_tokens_mistral': 1887, 'n_tokens_neox': 1832, 'n_words': 538}