[exo-jcr-commits] exo-jcr SVN: r3704 - jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Dec 22 05:54:30 EST 2010
Author: tolusha
Date: 2010-12-22 05:54:30 -0500 (Wed, 22 Dec 2010)
New Revision: 3704
Added:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java
Log:
EXOJCR-1102: add load test
Added: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java 2010-12-22 10:54:30 UTC (rev 3704)
@@ -0,0 +1,323 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero 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 Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.backup.load;
+
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.PropertiesParam;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.ext.backup.AbstractBackupTestCase;
+import org.exoplatform.services.jcr.ext.backup.BackupChain;
+import org.exoplatform.services.jcr.ext.backup.BackupChainLog;
+import org.exoplatform.services.jcr.ext.backup.BackupConfig;
+import org.exoplatform.services.jcr.ext.backup.BackupJob;
+import org.exoplatform.services.jcr.ext.backup.BackupManager;
+import org.exoplatform.services.jcr.ext.backup.ExtendedBackupManager;
+import org.exoplatform.services.jcr.ext.backup.impl.BackupManagerImpl;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+import org.exoplatform.services.jcr.impl.core.PropertyImpl;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.version.VersionException;
+import javax.jcr.version.VersionHistory;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy at gmail.com">Karpenko Sergiy</a>
+ * @version $Id: TestLoadBackup.java 111 2008-11-11 11:11:11Z serg $
+ */
+public class TestLoadBackup extends AbstractBackupTestCase
+{
+ protected final String REPOSITORY_NAME = "db7";
+
+ protected final String WORKSPACE_NAME = "ws1";
+
+ protected final int WRITER_COUNT = 100;
+
+ protected final String FULL_BACKUP_TYPE = "org.exoplatform.services.jcr.ext.backup.impl.rdbms.FullBackupJob";
+
+ protected final int BACKUP_TYPE = BackupManager.FULL_BACKUP_ONLY;
+
+ protected final boolean RESTORE_INTO_EXISTED = false;
+
+ protected ManageableRepository repository;
+
+ /**
+ * Writer.
+ */
+ class TreeWriterThread extends Thread
+ {
+ private Session session;
+
+ private final String nodeName;
+
+ public TreeWriterThread(Session session, String nodeName) throws RepositoryException
+ {
+ this.session = session;
+ this.nodeName = nodeName;
+ }
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ while (true)
+ {
+ Node rootChild = session.getRootNode().addNode(nodeName + System.currentTimeMillis());
+ session.save();
+
+ addChilds(session, rootChild, 0);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Test Backup/Restore.
+ *
+ * @throws Exception
+ */
+ public void testBackupRestore() throws Exception
+ {
+ BackupManagerImpl backupManagerImpl = null;
+
+ List<TreeWriterThread> threads = new ArrayList<TreeWriterThread>();
+ List<Session> sessions = new ArrayList<Session>();
+
+ //writers
+ for (int i = 0; i < WRITER_COUNT; i++)
+ {
+ Session writerSession = repository.login(credentials, WORKSPACE_NAME);
+ TreeWriterThread writer = new TreeWriterThread(writerSession, "subnode" + i);
+ writer.start();
+ threads.add(writer);
+ sessions.add(writerSession);
+ }
+
+ Thread.sleep(5 * 1000);
+
+ System.out.println(" ============ BACKUP START ============");
+
+ // backup
+ File backDir = new File("target/backup/ws1");
+ backDir.mkdirs();
+ BackupChain bch = null;
+
+ backupManagerImpl = (BackupManagerImpl)getBackupManager();
+ backupManagerImpl.start();
+
+ BackupConfig config = new BackupConfig();
+ config.setRepository(REPOSITORY_NAME);
+ config.setWorkspace(WORKSPACE_NAME);
+ config.setBackupType(BACKUP_TYPE);
+ config.setBackupDir(backDir);
+
+ backupManagerImpl.startBackup(config);
+
+ bch = backupManagerImpl.findBackup(REPOSITORY_NAME, WORKSPACE_NAME);
+
+ // wait till full backup will be stopped
+ while (bch.getFullBackupState() != BackupJob.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(30);
+ }
+
+ System.out.println(" ============ FULL BACKUP FINISHED ============");
+
+ if (BACKUP_TYPE == BackupManager.FULL_AND_INCREMENTAL)
+ {
+ Thread.sleep(30 * 1000);
+ }
+
+ // stop backup
+ if (bch != null)
+ {
+ backupManagerImpl.stopBackup(bch);
+ }
+ else
+ {
+ fail("Can't get fullBackup chain");
+ }
+ Thread.sleep(5 * 1000);
+
+ System.out.println(" ============ BACKUP FINISHED ============");
+
+ // for (Thread thread : threads)
+ // {
+ // thread.interrupt();
+ // }
+
+ // restore
+ WorkspaceEntry ws1back = makeWorkspaceEntry("ws1back", "jdbcjcr3");
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ BackupChainLog bchLog = new BackupChainLog(backLog);
+
+ System.out.println(" ============ RESTORE START ============");
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restore(bchLog, repositoryNameToBackup, ws1back, false);
+ }
+ else
+ {
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
+
+ System.out.println(" ============ CHECKING INTEGRITY ============");
+
+ checkIntegrity((NodeImpl)repositoryService.getRepository(repositoryNameToBackup).login(credentials, "ws1back")
+ .getRootNode());
+ }
+
+ protected void addChilds(Session session, Node root, int layer) throws Exception
+ {
+ if (layer == 4)
+ {
+ return;
+ }
+
+ for (int i = 0; i < 10; i++)
+ {
+ Node n = root.addNode("testNode" + i);
+ n.addMixin("mix:referenceable");
+ n.addMixin("mix:versionable");
+ n.setProperty("long", i);
+ n.setProperty("ref", n);
+ n.setProperty("string", new String[]{"test" + System.currentTimeMillis()});
+ n.setProperty("stream", new FileInputStream(createBLOBTempFile(1 * 1024)));
+
+ session.save();
+
+ n.checkin();
+ n.checkout();
+
+ Thread.sleep(50);
+
+ addChilds(session, n, layer + 1);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ExtendedBackupManager getBackupManager()
+ {
+ InitParams initParams = new InitParams();
+ PropertiesParam pps = new PropertiesParam();
+ pps.setProperty(BackupManagerImpl.FULL_BACKUP_TYPE, FULL_BACKUP_TYPE);
+ pps.setProperty(BackupManagerImpl.INCREMENTAL_BACKUP_TYPE,
+ "org.exoplatform.services.jcr.ext.backup.impl.fs.IncrementalBackupJob");
+ pps.setProperty(BackupManagerImpl.BACKUP_DIR, "target/backup");
+ pps.setProperty(BackupManagerImpl.DEFAULT_INCREMENTAL_JOB_PERIOD, "3600");
+
+ initParams.put(BackupManagerImpl.BACKUP_PROPERTIES, pps);
+
+ return new BackupManagerImpl(initParams, repositoryService);
+ }
+
+ /**
+ * Check integrity. Get all values from all properties.
+ *
+ * @param node
+ * @throws RepositoryException
+ */
+ protected void checkIntegrity(NodeImpl node) throws RepositoryException
+ {
+ Iterator<NodeImpl> iterator = node.getNodes();
+ while (iterator.hasNext())
+ {
+ NodeImpl newNode = iterator.next();
+ if (newNode.isNodeType(Constants.MIX_VERSIONABLE)
+ && !newNode.getData().getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH))
+ {
+ VersionHistory verHist = newNode.getVersionHistory();
+
+ NodeImpl verNode = null;
+ try
+ {
+ verNode = (NodeImpl)verHist.getVersion("1");
+ checkIntegrity(verNode);
+ }
+ catch (VersionException e)
+ {
+ }
+ }
+
+ checkIntegrity(newNode);
+
+ Iterator<PropertyImpl> propIt = newNode.getProperties();
+ while (propIt.hasNext())
+ {
+ PropertyImpl prop = propIt.next();
+ if (prop.isMultiValued())
+ {
+ for (Value value : prop.getValues())
+ {
+ value.toString();
+ }
+ }
+ else
+ {
+ prop.getValue().toString();
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ repository = repositoryService.getRepository(REPOSITORY_NAME);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void tearDown() throws Exception
+ {
+ }
+}
More information about the exo-jcr-commits
mailing list