Skip to content

Commit

Permalink
Fixed issue #3739
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Mar 11, 2015
1 parent dcb491b commit bc4a213
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 9 deletions.
Expand Up @@ -19,8 +19,10 @@
*/ */
package com.orientechnologies.orient.core.exception; package com.orientechnologies.orient.core.exception;


import com.orientechnologies.common.exception.OException;

@SuppressWarnings("serial") @SuppressWarnings("serial")
public class OValidationException extends RuntimeException { public class OValidationException extends OException {


public OValidationException(String string) { public OValidationException(String string) {
super(string); super(string);
Expand Down
Expand Up @@ -117,6 +117,7 @@ public abstract class OAbstractPaginatedStorage extends OStorageAbstract impleme
private final ConcurrentMap<String, OCluster> clusterMap = new ConcurrentHashMap<String, OCluster>(); private final ConcurrentMap<String, OCluster> clusterMap = new ConcurrentHashMap<String, OCluster>();
private final ThreadLocal<OStorageTransaction> transaction = new ThreadLocal<OStorageTransaction>(); private final ThreadLocal<OStorageTransaction> transaction = new ThreadLocal<OStorageTransaction>();
private final OModificationLock modificationLock = new OModificationLock(); private final OModificationLock modificationLock = new OModificationLock();
private final AtomicBoolean checkpointInProgress = new AtomicBoolean();
protected volatile OWriteAheadLog writeAheadLog; protected volatile OWriteAheadLog writeAheadLog;
protected volatile ODiskCache diskCache; protected volatile ODiskCache diskCache;
private ORecordConflictStrategy recordConflictStrategy = Orient.instance() private ORecordConflictStrategy recordConflictStrategy = Orient.instance()
Expand All @@ -125,16 +126,12 @@ public abstract class OAbstractPaginatedStorage extends OStorageAbstract impleme
private CopyOnWriteArrayList<OCluster> clusters = new CopyOnWriteArrayList<OCluster>(); private CopyOnWriteArrayList<OCluster> clusters = new CopyOnWriteArrayList<OCluster>();
private volatile int defaultClusterId = -1; private volatile int defaultClusterId = -1;
private volatile OAtomicOperationsManager atomicOperationsManager; private volatile OAtomicOperationsManager atomicOperationsManager;

private volatile boolean wereDataRestoredAfterOpen = false; private volatile boolean wereDataRestoredAfterOpen = false;
private volatile boolean wereNonTxOperationsPerformedInPreviousOpen = false; private volatile boolean wereNonTxOperationsPerformedInPreviousOpen = false;

private boolean makeFullCheckPointAfterClusterCreate = OGlobalConfiguration.STORAGE_MAKE_FULL_CHECKPOINT_AFTER_CLUSTER_CREATE private boolean makeFullCheckPointAfterClusterCreate = OGlobalConfiguration.STORAGE_MAKE_FULL_CHECKPOINT_AFTER_CLUSTER_CREATE
.getValueAsBoolean(); .getValueAsBoolean();

private volatile OLowDiskSpaceInformation lowDiskSpace = null; private volatile OLowDiskSpaceInformation lowDiskSpace = null;
private volatile boolean checkpointRequest = false; private volatile boolean checkpointRequest = false;
private final AtomicBoolean checkpointInProgress = new AtomicBoolean();


public OAbstractPaginatedStorage(String name, String filePath, String mode) { public OAbstractPaginatedStorage(String name, String filePath, String mode) {
super(name, filePath, mode, OGlobalConfiguration.STORAGE_LOCK_TIMEOUT.getValueAsInteger()); super(name, filePath, mode, OGlobalConfiguration.STORAGE_LOCK_TIMEOUT.getValueAsInteger());
Expand Down Expand Up @@ -909,9 +906,16 @@ public void commit(final OTransaction clientTx, Runnable callback) {


clientTx.clearRecordEntries(); clientTx.clearRecordEntries();


for (ORecordOperation txEntry : tmpEntries) for (ORecordOperation txEntry : tmpEntries) {
if (txEntry.type == ORecordOperation.CREATED || txEntry.type == ORecordOperation.UPDATED) {
final ORecord record = txEntry.getRecord();
if (record instanceof ODocument)
((ODocument) record).validate();
}

// COMMIT ALL THE SINGLE ENTRIES ONE BY ONE // COMMIT ALL THE SINGLE ENTRIES ONE BY ONE
commitEntry(clientTx, txEntry); commitEntry(clientTx, txEntry);
}
} }


if (callback != null) if (callback != null)
Expand Down
Expand Up @@ -18,13 +18,18 @@


package com.orientechnologies.orient.graph.blueprints; package com.orientechnologies.orient.graph.blueprints;


import org.junit.BeforeClass; import org.junit.Before;
import org.junit.Test; import org.junit.Test;


import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.exception.OValidationException;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType; import com.orientechnologies.orient.core.metadata.schema.OType;
import com.tinkerpop.blueprints.Direction; import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.impls.orient.OrientEdgeType; import com.tinkerpop.blueprints.impls.orient.OrientEdgeType;
import com.tinkerpop.blueprints.impls.orient.OrientGraph; import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import com.tinkerpop.blueprints.impls.orient.OrientVertex; import com.tinkerpop.blueprints.impls.orient.OrientVertex;
import com.tinkerpop.blueprints.impls.orient.OrientVertexType; import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
Expand All @@ -33,8 +38,8 @@ public class GraphValidationTest {


public static final String URL = "memory:" + GraphValidationTest.class.getSimpleName(); public static final String URL = "memory:" + GraphValidationTest.class.getSimpleName();


@BeforeClass @Before
public static void beforeClass() { public void beforeMethod() {
OrientGraph g = new OrientGraph(URL, "admin", "admin"); OrientGraph g = new OrientGraph(URL, "admin", "admin");
g.drop(); g.drop();
} }
Expand Down Expand Up @@ -72,4 +77,64 @@ public void testValidationOnVertices() {
g2.shutdown(); g2.shutdown();
} }
} }

@Test
public void ok() {
setupSchema();
final OrientGraphNoTx graphNoTx = new OrientGraphNoTx(URL, "admin", "admin");

graphNoTx.addVertex("class:M", "name", "n0");
try {
graphNoTx.addVertex("class:M");
throw new RuntimeException("Schema problem was not detected!");
} catch (Throwable e) {
// This is what happens => OK
System.out.println("This is the Message I want to see: \n" + e);
}

graphNoTx.commit();
graphNoTx.shutdown();
}

@Test
public void fail() {
setupSchema();
final OrientGraphFactory orientGraphFactory = new OrientGraphFactory(URL, "admin", "admin").setupPool(1, 10);
OrientGraph graph = orientGraphFactory.getTx();

graph.addVertex("class:M", "name", "n0");
try {
graph.addVertex("class:M");
graph.commit();
// This is what happens => not OK?
throw new RuntimeException("Schema problem was not detected!");
} catch (OValidationException e) {
System.out.println("This is the Message I want to see: \n" + e);
}

}

private void setupSchema() {
OrientGraphNoTx graphNoTx = new OrientGraphNoTx(URL, "admin", "admin");

ODatabaseDocumentTx database = graphNoTx.getRawGraph();
OSchema oScchema = database.getMetadata().getSchema();

oScchema.getClass("V").setStrictMode(true);
oScchema.getClass("E").setStrictMode(true);

OrientVertexType CmVertexBaseType = graphNoTx.createVertexType("CmVertexBase", "V");
CmVertexBaseType.setStrictMode(true);

OrientVertexType CmEdgeBaseType = graphNoTx.createVertexType("CmEdgeBase", "V");
CmEdgeBaseType.setStrictMode(true);

OClass mOClass = database.getMetadata().getSchema().createClass("M", database.getMetadata().getSchema().getClass("V"));
mOClass.createProperty("name", OType.STRING).setMandatory(true).setNotNull(true);
mOClass.setStrictMode(true);

graphNoTx.commit();
graphNoTx.shutdown();
}

} }

0 comments on commit bc4a213

Please sign in to comment.