Author: jcouteau Date: 2011-04-15 12:49:16 +0200 (Fri, 15 Apr 2011) New Revision: 810 Url: http://nuiton.org/repositories/revision/wikitty/810 Log: Use single Lock type Remove solrServerTest which goes b0rkz0r3d Removed: trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrServerTest.java Modified: trunk/wikitty-solr/src/main/resources/solrconfig.xml Modified: trunk/wikitty-solr/src/main/resources/solrconfig.xml =================================================================== --- trunk/wikitty-solr/src/main/resources/solrconfig.xml 2011-04-14 15:56:28 UTC (rev 809) +++ trunk/wikitty-solr/src/main/resources/solrconfig.xml 2011-04-15 10:49:16 UTC (rev 810) @@ -87,7 +87,7 @@ (For backwards compatibility with Solr 1.2, 'simple' is the default if not specified.) --> - <lockType>simple</lockType> + <lockType>single</lockType> </indexDefaults> <mainIndex> Deleted: trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrServerTest.java =================================================================== --- trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrServerTest.java 2011-04-14 15:56:28 UTC (rev 809) +++ trunk/wikitty-solr/src/test/java/org/nuiton/wikitty/storage/solr/SolrServerTest.java 2011-04-15 10:49:16 UTC (rev 810) @@ -1,217 +0,0 @@ -/* - * #%L - * Wikitty :: wikitty-solr-impl - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2010 CodeLutin, Benjamin Poussin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.wikitty.storage.solr; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; -import org.apache.solr.common.SolrDocument; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.core.CoreContainer; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Test behaviour SolrServer embedded. - * - * @author ruchaud - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ -public class SolrServerTest { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - private static final Log log = LogFactory.getLog(SolrServerTest.class); - - public SolrServer newSolrServer() throws Exception { - CoreContainer.Initializer initializer = new CoreContainer.Initializer(); - CoreContainer coreContainer = initializer.initialize(); - SolrServer solrServer = new EmbeddedSolrServer(coreContainer, ""); - return solrServer; - } - - public void addDocument(SolrServer solrServer, String id, String value) throws Exception { - SolrInputDocument document = new SolrInputDocument(); - document.setField(WikittySolrConstant.SOLR_ID, id); - document.setField(WikittySolrConstant.SOLR_EXTENSIONS, value); - solrServer.add(document); - } - - public static class ThreadAddDocument extends Thread { - protected SolrServer solrServer; - protected String identifier; - protected boolean commit; - - public ThreadAddDocument(SolrServer solrServer, String identifier, boolean commit) { - this.solrServer = solrServer; - this.identifier = identifier; - this.commit = commit; - } - - @Override - public void run() { - try { - for (Integer index = 0; index < 10; index++) { - SolrInputDocument document = new SolrInputDocument(); - document.setField(WikittySolrConstant.SOLR_ID, identifier); - document.setField(WikittySolrConstant.SOLR_EXTENSIONS, index.toString()); - solrServer.add(document); - if(commit) { - solrServer.commit(); - } else { - solrServer.rollback(); - } - } - } catch (Exception eee) { - throw new RuntimeException(eee); - } - } - } - - @Before - public void clearIndex() throws Exception { - SolrServer solrServer = newSolrServer(); - solrServer.deleteByQuery("*:*"); - solrServer.commit(); - } - - @Test(expected=SolrServerException.class) - public void testLockObtainFailed() throws Exception { - SolrServer solrServer1 = newSolrServer(); - SolrServer solrServer2 = newSolrServer(); - - addDocument(solrServer1, "1", "1"); - addDocument(solrServer2, "2", "2"); - } - - /* - * FIXME le 21/02/2010 par sch - * Le test est mauvais par nature (je crois), car: - * - thread1 et thread2 ajoutent simultanement des documents - * - thread1 et thread2 commit ou rollback simultanement - * Il est impossible de savoir s'il y aura zero, un, ou deux documents à la fin. - * De plus ce test est la seule cause des erreurs de build de ces derniers temps. - * Et il y a un commentaire laissant planer le doute un peu plus bas. - */ - @Ignore - @Test - public void test2Threads1SolrServer() throws Exception { - SolrServer solrServer = newSolrServer(); - - ThreadAddDocument thread1 = new ThreadAddDocument(solrServer, "1", true); - ThreadAddDocument thread2 = new ThreadAddDocument(solrServer, "2", false); - - thread1.start(); - thread2.start(); - - Thread.sleep(3000); - - SolrDocument result = SolrUtil.findById(solrServer, "1"); - assertNotNull(result); - - // Normaly the value is null, if SolrServer is thread safe - result = SolrUtil.findById(solrServer, "2"); - assertNotNull(result); - } - - @Test - public void test2Threads1Writer2SolrServers() throws Exception { - SolrServer solrServer1 = newSolrServer(); - SolrServer solrServer2 = newSolrServer(); - - ThreadAddDocument thread1 = new ThreadAddDocument(solrServer1, "1", true); - ThreadAddDocument thread2 = new ThreadAddDocument(solrServer2, "2", false); - - thread1.start(); - thread2.start(); - - Thread.sleep(3000); - - SolrDocument result = SolrUtil.findById(solrServer1, "1"); - assertNotNull(result); - - result = SolrUtil.findById(solrServer2, "2"); - assertNull(result); - - SolrServer solrServer3 = newSolrServer(); - result = SolrUtil.findById(solrServer3, "1"); - assertNotNull(result); - result = SolrUtil.findById(solrServer3, "2"); - assertNull(result); - } - - //FIXME poussin 2010 07 21 : regarder pourquoi meêm si on attend les threads, ils sont mal synchronises - @Ignore - @Test - public void test2Threads2Writers2SolrServers() throws Exception { - SolrServer solrServer1 = newSolrServer(); - SolrServer solrServer2 = newSolrServer(); - - ThreadAddDocument thread1 = new ThreadAddDocument(solrServer1, "1", true); - ThreadAddDocument thread2 = new ThreadAddDocument(solrServer2, "2", true); - - thread1.start(); - thread2.start(); - -// Thread.sleep(3000); - thread1.join(); - thread2.join(); - - SolrDocument result = SolrUtil.findById(solrServer1, "1"); - assertNotNull(result); - - result = SolrUtil.findById(solrServer2, "2"); - assertNotNull(result); - - SolrServer solrServer3 = newSolrServer(); - result = SolrUtil.findById(solrServer3, "1"); - assertNotNull(result); - result = SolrUtil.findById(solrServer3, "2"); - assertNotNull(result); - } - - @Ignore // FIXME 20100806 bleny randomly fail - @Test - public void testReader() throws Exception { - SolrServer solrServer1 = newSolrServer(); - SolrServer solrServer2 = newSolrServer(); - - addDocument(solrServer1, "1", "1"); - solrServer1.commit(); - - SolrDocument result = SolrUtil.findById(solrServer2, "1"); - assertNull(result); - } - -}
participants (1)
-
jcouteau@users.nuiton.org