| package org.eclipse.papyrus.cdo.uml.benchmarks.creation.tests.cleanexamples; |
| |
| import org.eclipse.emf.cdo.net4j.CDONet4jSession; |
| import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration; |
| import org.eclipse.emf.cdo.net4j.CDONet4jUtil; |
| import org.eclipse.emf.cdo.session.CDOSession; |
| import org.eclipse.emf.cdo.transaction.CDOTransaction; |
| import org.eclipse.emf.cdo.view.CDOView; |
| import org.eclipse.emf.ecore.resource.Resource; |
| import org.eclipse.net4j.Net4jUtil; |
| import org.eclipse.net4j.connector.IConnector; |
| import org.eclipse.net4j.signal.ISignalProtocol; |
| import org.eclipse.net4j.tcp.TCPUtil; |
| import org.eclipse.net4j.util.container.IPluginContainer; |
| import org.eclipse.net4j.util.om.OMPlatform; |
| import org.eclipse.net4j.util.security.PasswordCredentialsProvider; |
| import org.eclipse.uml2.uml.Package; |
| import org.eclipse.uml2.uml.UMLFactory; |
| import org.junit.Assert; |
| |
| public class CDORemoteTests_ManyCommit_OneTransaction_NoSubPackage { |
| |
| private static final UMLFactory FACTORY = UMLFactory.eINSTANCE; |
| |
| // @Test |
| public void create_10000_Elements() throws Exception { |
| create_Elements(10000); |
| } |
| |
| // @Test |
| public void create_50000_Elements() throws Exception { |
| create_Elements(50000); |
| } |
| |
| // @Test |
| public void create_500000_Elements() throws Exception { |
| create_Elements(500000); |
| } |
| |
| // @Test |
| public void create_1000000_Elements() throws Exception { |
| create_Elements(1000000); |
| } |
| |
| |
| private void create_Elements(int size) throws Exception { |
| System.out.println("Class Tests Name:" + getClass().getSimpleName()); |
| System.out.println("Creation in Remote CDO file"); |
| System.out.println("Creating " + size + " elements with the factory " + FACTORY.getClass().getName() + "..."); |
| String fileName = size + "_Elements"; |
| String timsestamp = Long.toString(System.currentTimeMillis()); |
| fileName = fileName + "_" + timsestamp; |
| |
| CDOSession session = openSession(); |
| CDOTransaction transaction = session.openTransaction(); |
| Resource myResource = transaction.getOrCreateResource("/home/Administrator/" + fileName); |
| |
| |
| ///////////////////////////////// CREATE ////////////////////////////////////////////////////// |
| long start = System.currentTimeMillis(); |
| |
| // 1. create the root package |
| org.eclipse.uml2.uml.Package rootPackage = FACTORY.createPackage(); |
| rootPackage.setName("RootPackage_" + fileName); |
| myResource.getContents().add(rootPackage); |
| |
| int nbClassPerLoop = 1000; |
| |
| // 2. create the elements |
| for (int i = 0; i < size; i += nbClassPerLoop) { |
| createElementsInNewPackage(fileName, i, nbClassPerLoop, rootPackage); |
| transaction.commit(); |
| } |
| |
| long end = System.currentTimeMillis(); |
| System.out.println("Done: " + (end - start) + " ms "); |
| |
| ///////////////////////////////// SAVE ////////////////////////////////////////////////////// |
| System.out.println("Committing... (there as intermediate commit with this process)"); |
| start = System.currentTimeMillis(); |
| |
| transaction.commit(); |
| session.close(); |
| |
| end = System.currentTimeMillis(); |
| System.out.println("Done: " + (end - start) + " ms"); |
| |
| |
| |
| ///////////////////////////////// LOAD ////////////////////////////////////////////////////// |
| CDOSession session2 = openSession(); |
| CDOView view = session2.openView(); |
| Resource resource2 = view.getResource("/home/Administrator/" + fileName); |
| |
| System.out.println("Loading root object..."); |
| start = System.currentTimeMillis(); |
| org.eclipse.uml2.uml.Package p = (org.eclipse.uml2.uml.Package) resource2.getContents().get(0); |
| end = System.currentTimeMillis(); |
| Assert.assertNotNull(p); |
| System.out.println("Done: " + (end - start) + " ms"); |
| System.out.println("\n\n\n"); |
| |
| session2.close(); |
| } |
| |
| private void createElementsInNewPackage(final String fileName, final int packIndex, final int nbClassToCreate, Package pack) { |
| // 3. we create an intermediate package |
| Package currentPackage = pack; |
| // UMLFactory.eINSTANCE.createPackage(); |
| // currentPackage.setName("package" + packIndex); |
| // pack.getPackagedElements().add(currentPackage); |
| long start = System.currentTimeMillis(); |
| |
| // we create nbClasses |
| for (int i = 0; i < nbClassToCreate; i++) { |
| org.eclipse.uml2.uml.Class aclass = UMLFactory.eINSTANCE.createClass(); |
| final StringBuilder builder = new StringBuilder("Class_"); |
| builder.append(i); |
| aclass.setName(builder.toString()); |
| currentPackage.getPackagedElements().add(aclass); |
| } |
| |
| long end = System.currentTimeMillis(); |
| // System.out.println(" " + nbClassToCreate + " created in " + (end - start) + " ms"); |
| } |
| |
| //================== CDO ============================================== |
| |
| static { |
| if (!OMPlatform.INSTANCE.isOSGiRunning()) { |
| Net4jUtil.prepareContainer(IPluginContainer.INSTANCE); // Register Net4j factories |
| TCPUtil.prepareContainer(IPluginContainer.INSTANCE); // Register TCP factories |
| CDONet4jUtil.prepareContainer(IPluginContainer.INSTANCE); // Register CDO factories |
| IPluginContainer.INSTANCE.activate(); |
| } |
| } |
| |
| private static final String HOST_AND_PORT = "localhost:2036"; |
| private static final String USER_NAME = "Administrator"; |
| private static final String PASSWORD = "0000"; |
| private static final String PAPYRUS_CDO_SECURED_REPOSITORY = "PapyrusCDOSecuredRepository"; |
| |
| |
| private CDOSession openSession() throws Exception { |
| IConnector connector = TCPUtil.getConnector(IPluginContainer.INSTANCE, HOST_AND_PORT); |
| |
| CDONet4jSessionConfiguration configuration = CDONet4jUtil.createNet4jSessionConfiguration(); |
| configuration.setConnector(connector); |
| configuration.setRepositoryName(PAPYRUS_CDO_SECURED_REPOSITORY); |
| configuration.setCredentialsProvider(new PasswordCredentialsProvider(USER_NAME, PASSWORD)); |
| CDONet4jSession session = configuration.openNet4jSession(); |
| session.options().getNet4jProtocol().setTimeout(ISignalProtocol.NO_TIMEOUT); |
| |
| return session; |
| } |
| } |