<commit_before>/*
 * Copyright 1999-2010 <NAME> (l.garulli--at--orientechnologies.com)
 *
 * 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.orientechnologies.orient.test.database.auto;

import java.util.List;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import com.orientechnologies.common.concur.ONeedRetryException;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;

@Test
public class ConcurrentQueriesTest {
	private final static int	THREADS	= 10;
	protected String					url;
	private boolean						level1CacheEnabled;
	private boolean						level2CacheEnabled;
	private boolean						mvccEnabled;

	static class CommandExecutor implements Runnable {

		String	url;
		String	threadName;

		public CommandExecutor(String url, String iThreadName) {
			super();
			this.url = url;
			threadName = iThreadName;
		}

		public void run() {
			try {
				for (int i = 0; i < 50; i++) {
					ODatabaseDocumentTx db = new ODatabaseDocumentTx(url).open("admin", "admin");
					try {
						while (true) {
							try {
								List<ODocument> result = db.command(new OCommandSQL("select from Concurrent")).execute();
								System.out.println("Thread " + threadName + " result = " + result.size());
								break;
							} catch (ONeedRetryException e) {
								// e.printStackTrace();
								System.out.println("Retry...");
							}
						}
					} finally {
						db.close();
					}
				}

			} catch (Throwable e) {
				e.printStackTrace();
			}
		}
	}

	@Parameters(value = "url")
	public ConcurrentQueriesTest(@Optional(value = "memory:test") String iURL) {
		url = iURL;
	}

	@BeforeClass
	public void init() {
		level1CacheEnabled = OGlobalConfiguration.CACHE_LEVEL1_ENABLED.getValueAsBoolean();
		level2CacheEnabled = OGlobalConfiguration.CACHE_LEVEL2_ENABLED.getValueAsBoolean();
		mvccEnabled = OGlobalConfiguration.DB_MVCC.getValueAsBoolean();

		if (level1CacheEnabled)
			OGlobalConfiguration.CACHE_LEVEL1_ENABLED.setValue(false);
		if (level2CacheEnabled)
			OGlobalConfiguration.CACHE_LEVEL2_ENABLED.setValue(false);
		if (!mvccEnabled)
			OGlobalConfiguration.DB_MVCC.setValue(true);

		if ("memory:test".equals(url))
			new ODatabaseDocumentTx(url).create().close();

		ODatabaseDocumentTx db = new ODatabaseDocumentTx(url).open("admin", "admin");
		db.getMetadata().getSchema().createClass("Concurrent");

		for (int i = 0; i < 1000; ++i) {
			db.newInstance("Concurrent").field("test", i).save();
		}
	}

	@AfterClass
	public void deinit() {
		OGlobalConfiguration.CACHE_LEVEL1_ENABLED.setValue(level1CacheEnabled);
		OGlobalConfiguration.CACHE_LEVEL2_ENABLED.setValue(level2CacheEnabled);
		OGlobalConfiguration.DB_MVCC.setValue(mvccEnabled);
	}<commit_msg>Changed test case to test open+query+close with 100 threads to find the problem of Algirdas reported in ML. Now I've removed cache management<commit_after>/*
 * Copyright 1999-2010 <NAME> (l.garulli--at--orientechnologies.com)
 *
 * 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.orientechnologies.orient.test.database.auto;

import java.util.List;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import com.orientechnologies.common.concur.ONeedRetryException;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;

@Test
public class ConcurrentQueriesTest {
	private final static int	THREADS	= 10;
	protected String					url;
	private boolean						level1CacheEnabled;
	private boolean						level2CacheEnabled;
	private boolean						mvccEnabled;

	static class CommandExecutor implements Runnable {

		String	url;
		String	threadName;

		public CommandExecutor(String url, String iThreadName) {
			super();
			this.url = url;
			threadName = iThreadName;
		}

		public void run() {
			try {
				for (int i = 0; i < 50; i++) {
					ODatabaseDocumentTx db = new ODatabaseDocumentTx(url).open("admin", "admin");
					try {
						while (true) {
							try {
								List<ODocument> result = db.command(new OCommandSQL("select from Concurrent")).execute();
								System.out.println("Thread " + threadName + " result = " + result.size());
								break;
							} catch (ONeedRetryException e) {
								// e.printStackTrace();
								System.out.println("Retry...");
							}
						}
					} finally {
						db.close();
					}
				}

			} catch (Throwable e) {
				e.printStackTrace();
			}
		}
	}

	@Parameters(value = "url")
	public ConcurrentQueriesTest(@Optional(value = "memory:test") String iURL) {
		url = iURL;
	}

	@BeforeClass
	public void init() {
		if ("memory:test".equals(url))
			new ODatabaseDocumentTx(url).create().close();

		ODatabaseDocumentTx db = new ODatabaseDocumentTx(url).open("admin", "admin");
		db.getMetadata().getSchema().createClass("Concurrent");

		for (int i = 0; i < 1000; ++i) {
			db.newInstance("Concurrent").field("test", i).save();
		}
	}
{'fraction_non_alphanumeric': 0.111230274245442, 'fraction_numerical': 0.00965221388080282, 'mean_word_length': 3.9908256880733943, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '6082721', 'n_tokens_mistral': 2274, 'n_tokens_neox': 1943, 'n_words': 488}