Author: glandais Date: 2008-02-29 16:43:35 +0000 (Fri, 29 Feb 2008) New Revision: 1260 Removed: trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceMassInsert.java Modified: trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsTestCase.java Log: Update to use StorageServiceGenerator Deleted: trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceMassInsert.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceMassInsert.java 2008-02-29 16:43:11 UTC (rev 1259) +++ trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceMassInsert.java 2008-02-29 16:43:35 UTC (rev 1260) @@ -1,131 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* This program 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 2 -* 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, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.service; - -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Random; - -import javax.naming.Context; -import javax.naming.InitialContext; - -import junit.framework.TestCase; - -import com.healthmarketscience.rmiio.SerializableInputStream; - -import fr.cemagref.simexplorer.is.entities.attachment.Attachment; -import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; -import fr.cemagref.simexplorer.is.entities.data.LoggableElement; -import fr.cemagref.simexplorer.is.factories.LoggableElementFactory; -import fr.cemagref.simexplorer.is.storage.ElementGenerator; -import fr.cemagref.simexplorer.is.storage.ElementGenerator.RandomStream; - -/** - * The Class StorageServiceMassInsert. - */ -public class StorageServiceMassInsert extends TestCase { - - /** The storage service. */ - private StorageService storageService; - - /** The element generator. */ - private ElementGenerator elementGenerator; - - /** The r. */ - private Random r = new Random(); - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - elementGenerator = new ElementGenerator(); - - Properties properties = (Properties) System.getProperties().clone(); - properties.put("java.naming.provider.url", "jnp://localhost:1099"); - properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); - properties.put("java.naming.factory.url.pkgs", "org.jnp.interfaces"); - - Context context = new InitialContext(properties); - storageService = (StorageService) context.lookup("StorageService"); - } - - /** - * Test mass insert. - * - * @throws Exception the exception - */ - public void testMassInsert() throws Exception { - int c = 5; - - String token = storageService.loginUser("superadmin", "password"); - - Date begin = new Date(); - - for (int i = 0; i < c; i++) { - ExplorationApplication parentEa; - parentEa = elementGenerator.generateRandomEA(); - - int v = 2 + r.nextInt(5); - - for (int j = 0; j < v; j++) { - ExplorationApplication ea = elementGenerator.generateRandomEA(); - ea.getMetaData().setUuid(parentEa.getMetaData().getUuid()); - ea.getMetaData().setVersion(parentEa.getMetaData().getVersion().toString()); - - ea.getMetaData().setVersion(ea.getMetaData().getVersion().incVersion(r.nextInt(3)).toString()); - - Map<Attachment, SerializableInputStream> attachments = new HashMap<Attachment, SerializableInputStream>(); - - List<Attachment> attachmentsKeys = new ArrayList<Attachment>(); - - attachmentsKeys.addAll(ea.getAttachments()); - List<LoggableElement> children = ea.getChildren(); - for (LoggableElement child : children) { - attachmentsKeys.addAll(child.getAttachments()); - } - - for (Attachment attachment : attachmentsKeys) { - RandomStream randomStream = elementGenerator.generateTextStream(); - attachment.setDataHash(randomStream.getMd5()); - SerializableInputStream stream = new SerializableInputStream(randomStream.getStream()); - attachments.put(attachment, stream); - } - - SerializableInputStream xmlStream = new SerializableInputStream(LoggableElementFactory.getStream(ea)); - - storageService.saveElement(token, xmlStream, attachments); - } - - if (i > 0 && i % 100 == 0) { - Date end = new Date(); - long time = end.getTime() - begin.getTime(); - System.out.println("Insert " + i + " : Time taken : " + time + "ms"); - double timePerElement = time / i; - System.out.println("Insert " + i + " : Time taken per element : " + timePerElement + "ms"); - } - - } - } - -} Modified: trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsTestCase.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsTestCase.java 2008-02-29 16:43:11 UTC (rev 1259) +++ trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsTestCase.java 2008-02-29 16:43:35 UTC (rev 1260) @@ -1,20 +1,20 @@ /* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* This program 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 2 -* 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, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ + * ##% Copyright (C) 2008 Code Lutin, Gabriel Landais + * + * This program 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##% */ package fr.cemagref.simexplorer.is.service; import java.util.ArrayList; @@ -50,79 +50,39 @@ /** The storage service. */ protected StorageService storageService; - /** The element generator. */ - protected ElementGenerator elementGenerator; - /** The token. */ protected String token; + + protected StorageServiceGenerator storageServiceGenerator; - /** The attachments. */ - private Map<Attachment, ElementGenerator.RandomStream> attachments; - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see junit.framework.TestCase#setUp() */ @Override protected void setUp() throws Exception { super.setUp(); - elementGenerator = new ElementGenerator(); - buildStorageService(); + storageServiceGenerator = new StorageServiceGenerator(); } /** * Builds the storage service. * - * @throws Exception the exception + * @throws Exception + * the exception */ protected abstract void buildStorageService() throws Exception; /** - * Save ea. - * - * @param ea the ea - * @param computeAttachments the compute attachments - * - * @return the meta data - * - * @throws Exception the exception - */ - private MetaData saveEa(ExplorationApplication ea, boolean computeAttachments) throws Exception { - - if (computeAttachments) { - attachments = new HashMap<Attachment, ElementGenerator.RandomStream>(); - - List<Attachment> attachmentsKeys = new ArrayList<Attachment>(); - - attachmentsKeys.addAll(ea.getAttachments()); - List<LoggableElement> children = ea.getChildren(); - for (LoggableElement child : children) { - attachmentsKeys.addAll(child.getAttachments()); - } - - for (Attachment attachment : attachmentsKeys) { - RandomStream randomStream = elementGenerator.generateTextStream(); - attachment.setDataHash(randomStream.getMd5()); - attachments.put(attachment, randomStream); - } - } - - SerializableInputStream xmlStream = new SerializableInputStream(LoggableElementFactory.getStream(ea)); - - Map<Attachment, SerializableInputStream> realAttachments = new HashMap<Attachment, SerializableInputStream>(); - for (Map.Entry<Attachment, ElementGenerator.RandomStream> element : attachments.entrySet()) { - realAttachments.put(element.getKey(), new SerializableInputStream(element.getValue().getStream())); - } - - return storageService.saveElement(token, xmlStream, realAttachments); - } - - /** * List existing. * - * @param uuid the uuid + * @param uuid + * the uuid * - * @throws SimExplorerException the sim explorer exception + * @throws SimExplorerException + * the sim explorer exception */ private void listExisting(String uuid) throws SimExplorerException { if (uuid != null) { @@ -137,107 +97,51 @@ /** * Test version update. * - * @param firstVersion the first version - * @param secondVersion the second version - * @param different the different - * @param versions the versions + * @param firstVersion + * the first version + * @param secondVersion + * the second version + * @param different + * the different + * @param versions + * the versions * * @return the string * - * @throws Exception the exception + * @throws Exception + * the exception */ protected String testVersionUpdate(String firstVersion, String secondVersion, boolean different, String... versions) - throws Exception { - System.out.println("-----------------------------"); + throws Exception { + String uuid = storageServiceGenerator.generateTwoExplorationApplications(storageService, token, firstVersion, secondVersion, different); + Version[] fundVersions = storageService.getVersions(token, uuid); - ExplorationApplication ea; - - ea = elementGenerator.generateRandomEA(); - - StringBuffer task = new StringBuffer(); - task.append(firstVersion).append("A + ").append(secondVersion); - if (different) { - task.append("B"); - } else { - task.append("A"); - } - - task.append(" = "); - - int i = 0; - for (String version : versions) { - if (i != 0) { - task.append(" + "); - } - task.append(version); - i++; - } - - System.out.println(task.toString()); - - System.out.println("UUID : " + ea.getMetaData().getUuid()); - System.out.println("Name : " + ea.getMetaData().getName()); - - ea.getMetaData().setVersion(firstVersion); - - System.out.println("Saving " + firstVersion + "A"); - MetaData mde1 = saveEa(ea, true); - listExisting(ea.getMetaData().getUuid()); - - ea.getMetaData().setVersion(secondVersion); - - if (different) { - Component component = ea.getComponents().iterator().next(); - Code code = new Code(); - code.setCode("regreg"); - code.setLanguage("regreg"); - component.getCodes().add(code); - } - - System.out.print("Saving " + secondVersion); - if (different) { - System.out.println("B"); - } else { - System.out.println("A"); - } - MetaData mde2 = saveEa(ea, false); - listExisting(ea.getMetaData().getUuid()); - - System.out.println("A : " + mde1.getHash()); - if (different) { - System.out.println("B : " + mde2.getHash()); - } - - Version[] fundVersions = storageService.getVersions(token, ea.getMetaData().getUuid()); - Set<Version> expectedVersionSet = new HashSet<Version>(); for (String versionExpected : versions) { expectedVersionSet.add(Version.valueOf(versionExpected)); } - Set<Version> fundVersionSet = new HashSet<Version>(); fundVersionSet.addAll(ArrayUtil.asList(fundVersions)); - - //assertTrue(SetUtils.isEqualSet(expectedVersionSet, fundVersionSet)); - - return ea.getMetaData().getUuid(); - // assertEquals(mde1.getVersion().toString(), assertFirst); - // assertEquals(mde2.getVersion().toString(), assertSecond); + // assertTrue(SetUtils.isEqualSet(expectedVersionSet, fundVersionSet)); + return uuid; } /** * Login on service. * - * @throws Exception the exception + * @throws Exception + * the exception */ protected abstract void loginOnService() throws Exception; /** * Versions test. * - * @param uuids the uuids + * @param uuids + * the uuids * - * @throws Exception the exception + * @throws Exception + * the exception */ protected abstract void versionsTest(List<String> uuids) throws Exception; @@ -247,11 +151,12 @@ * @return the iterations */ protected abstract int getIterations(); - + /** * Test version update. * - * @throws Exception the exception + * @throws Exception + * the exception */ public void testVersionUpdate() throws Exception { @@ -261,8 +166,8 @@ for (int i = 0; i < getIterations(); i++) { System.out.println("Iteration " + i); - versionsTest(uuids); - } + versionsTest(uuids); + } System.out.println("-----------------------------"); for (String uuid : uuids) {