<commit_before>/**
 * 
 * Copyright (c) 2005-2011, AtKaaZ
 * All rights reserved.
 * this file is part of DemLinks
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * * Neither the name of 'DemLinks' nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package org.bdb;


import static org.junit.Assert.*;

import org.dml.storage.berkeleydb.generics.*;
import org.junit.*;
import org.q.*;



public class TestBDBEnvironment
{
	
	@Test
	public void testUNG() {
		StorageBDBGeneric env = null;
		try {
			env = GlobalBDB.factory.getNewStorage( JUnitConstants.BDB_ENVIRONMENT_STORE_DIR, true );
			
			final String sameName = "some name";
			final int delta = +1;
			final long max = 10;
			final long min = -201;
			final long initialValue = -6;
			final Named_UniqueNumberGenerator ung =
				new Named_UniqueNumberGenerator( env, sameName, min, initialValue, max, false );
			long l1 = ung.getNextUniqueLong( delta );
			
			assertTrue( initialValue == l1 );
			final Named_UniqueNumberGenerator ung2 =
				new Named_UniqueNumberGenerator( env, sameName, min, initialValue, max, false );
			final long l2 = ung2.getNextUniqueLong( delta );
			// System.out.println( ung + " / " + ung2 );
			assertTrue( ung2 != ung );// they are same internally in BDB though.
			// assertTrue( ung2.equals( ung ) );
			
			try {
				ung2.equals( ung );// not implemented
				fail( "should've thrown" );// FIXME: i forgot why this is bad; and throw null; is better
			} catch ( final BadCallError bce ) {
				// this is right
			}
			
			final long expected = ( initialValue + ( 1 * delta ) );
			assertTrue( "got:" + l2 + " instead of " + expected, expected == l2 );
			assertTrue( l1 != l2 );
			assertTrue( ( l1 + delta ) == l2 );
			l1 = ung.getNextUniqueLong( delta );
			assertTrue( l1 == ( initialValue + ( 2 * delta ) ) );
			
			l1 = ung.getNextUniqueLong( delta );
			assertTrue( l1 == ( initialValue + ( 3 * delta ) ) );
			
			for ( int i = 0; i < ( ( max - 3 ) - initialValue ); i++ ) {
				l1 = ung.getNextUniqueLong( delta );
				// System.out.println( "l1==" + l1 );
				assertTrue( l1 == ( ( ( 4 + i ) * delta ) + initialValue ) );
			}
			
			try {
				l1 = ung.getNextUniqueLong( delta );
				Q.fail();
			} catch ( final Throwable soe ) {
				// right
				if ( !Q.isBareException( soe, SequenceOverflow.class ) ) {
					Q.rethrow( soe );
				}
			}
			
		} finally {
			if ( null != env ) {
				env.shutdown();
			}
		}
		StorageBDBGeneric env3 = null;
		StorageBDBGeneric env5 = null;
		try {
			env3 = GlobalBDB.factory.getNewStorage( JUnitConstants.BDB_ENVIRONMENT_STORE_DIR, false );
			try {
				env5 = GlobalBDB.factory.getNewStorage( JUnitConstants.BDB_ENVIRONMENT_STORE_DIR, false );
				Q.fail();
			} catch ( final Throwable t ) {
				if ( Q.isBareException( t, BadCallError.class ) ) {
				} else {
					Q.rethrow( t );
				}
			}
			
		} finally {
			if ( null != env3 ) {
				env3.shutdown( true );
			}
		}
		assertTrue( null == env5 );
	}<commit_msg>exception renamed<commit_after>/**
 * 
 * Copyright (c) 2005-2011, AtKaaZ
 * All rights reserved.
 * this file is part of DemLinks
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * * Neither the name of 'DemLinks' nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package org.bdb;


import static org.junit.Assert.*;

import org.dml.storage.berkeleydb.generics.*;
import org.junit.*;
import org.q.*;



public class TestBDBEnvironment
{
	
	@Test
	public void testUNG() {
		StorageBDBGeneric env = null;
		try {
			env = GlobalBDB.factory.getNewStorage( JUnitConstants.BDB_ENVIRONMENT_STORE_DIR, true );
			
			final String sameName = "some name";
			final int delta = +1;
			final long max = 10;
			final long min = -201;
			final long initialValue = -6;
			final Named_UniqueNumberGenerator ung =
				new Named_UniqueNumberGenerator( env, sameName, min, initialValue, max, false );
			long l1 = ung.getNextUniqueLong( delta );
			
			assertTrue( initialValue == l1 );
			final Named_UniqueNumberGenerator ung2 =
				new Named_UniqueNumberGenerator( env, sameName, min, initialValue, max, false );
			final long l2 = ung2.getNextUniqueLong( delta );
			// System.out.println( ung + " / " + ung2 );
			assertTrue( ung2 != ung );// they are same internally in BDB though.
			// assertTrue( ung2.equals( ung ) );
			
			try {
				ung2.equals( ung );// not implemented
				fail( "should've thrown" );// FIXME: i forgot why this is bad; and throw null; is better
			} catch ( final BadCallError bce ) {
				// this is right
			}
			
			final long expected = ( initialValue + ( 1 * delta ) );
			assertTrue( "got:" + l2 + " instead of " + expected, expected == l2 );
			assertTrue( l1 != l2 );
			assertTrue( ( l1 + delta ) == l2 );
			l1 = ung.getNextUniqueLong( delta );
			assertTrue( l1 == ( initialValue + ( 2 * delta ) ) );
			
			l1 = ung.getNextUniqueLong( delta );
			assertTrue( l1 == ( initialValue + ( 3 * delta ) ) );
			
			for ( int i = 0; i < ( ( max - 3 ) - initialValue ); i++ ) {
				l1 = ung.getNextUniqueLong( delta );
				// System.out.println( "l1==" + l1 );
				assertTrue( l1 == ( ( ( 4 + i ) * delta ) + initialValue ) );
			}
			
			try {
				l1 = ung.getNextUniqueLong( delta );
				Q.fail();
			} catch ( final Throwable soe ) {
				// right
				if ( !Q.isBareException( soe, SequenceOverflow_BDBException.class ) ) {
					Q.rethrow( soe );
				}
			}
			
		} finally {
			if ( null != env ) {
				env.shutdown();
			}
		}
		StorageBDBGeneric env3 = null;
		StorageBDBGeneric env5 = null;
		try {
			env3 = GlobalBDB.factory.getNewStorage( JUnitConstants.BDB_ENVIRONMENT_STORE_DIR, false );
			try {
				env5 = GlobalBDB.factory.getNewStorage( JUnitConstants.BDB_ENVIRONMENT_STORE_DIR, false );
				Q.fail();
			} catch ( final Throwable t ) {
				if ( Q.isBareException( t, BadCallError.class ) ) {
				} else {
					Q.rethrow( t );
				}
			}
			
		} finally {
			if ( null != env3 ) {
				env3.shutdown( true );
			}
		}
		assertTrue( null == env5 );
	}
{'fraction_non_alphanumeric': 0.10282420749279539, 'fraction_numerical': 0.011988472622478387, 'mean_word_length': 3.123574144486692, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3008895', 'n_tokens_mistral': 3108, 'n_tokens_neox': 2606, 'n_words': 931}