Skip to content

Commit

Permalink
Added comment with link to issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lucafrosini committed Apr 21, 2017
1 parent 34b6633 commit 17e8a24
Show file tree
Hide file tree
Showing 10 changed files with 482 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>orientdb-bug-reports</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
6 changes: 6 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
5 changes: 5 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
39 changes: 39 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.orientdb</groupId>
<artifactId>orientdb-bug-reports</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>OrientDB Bug Reports</name>
<description>This project is used to create reproducibility tests for bugs opened to orientdb project</description>


<properties>
<java_version>1.8</java_version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-graphdb</artifactId>
<version>2.2.18</version>
</dependency>
</dependencies>

<build>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<target>${java_version}</target>
<source>${java_version}</source>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
169 changes: 169 additions & 0 deletions src/main/java/org/gcube/orientdb/ReproduceBug7354.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/**
*
*/
package org.gcube.orientdb;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import com.orientechnologies.orient.client.remote.OServerAdmin;
import com.orientechnologies.orient.client.remote.OStorageRemote;
import com.orientechnologies.orient.core.metadata.OMetadata;
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.record.impl.ODocument;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientEdgeType;
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.OrientVertex;
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;

/**
* @author Luca Frosini (ISTI - CNR)
* This class reproduce orient issue 7354 - https://github.com/orientechnologies/orientdb/issues/7354
*/
public class ReproduceBug7354 {

private static final String HOST = "remote:node01.acme.org;node02.acme.org;node03.acme.org";
private static final String ROOT_USERNAME = "root";
private static final String ROOT_PASSWORD = "ROOT_PWD";

private static final String ADMIN_USERNAME = "admin";
private static final String ADMIN_PASSWORD = "admin";

private static final String DB_NAME = "mydb";

private static final String DATABASE_TYPE = "graph";
private static final String STORAGE_MODE = "plocal";

public static final String MEMORY_FACET = "MemoryFacet";

public UUID createDBTypesAndContext() throws IOException{

System.out.println("Going to create DB " + DB_NAME);

OServerAdmin serverAdmin = new OServerAdmin(HOST)
.connect(ROOT_USERNAME,ROOT_PASSWORD);

serverAdmin.createDatabase(DB_NAME, DATABASE_TYPE,
STORAGE_MODE);

OrientGraphFactory factory = new OrientGraphFactory(HOST + "/" + DB_NAME,
ADMIN_USERNAME, ADMIN_PASSWORD).setupPool(1, 10);

OrientGraphNoTx orientGraphNoTx = factory.getNoTx();

OMetadata oMetadata = orientGraphNoTx.getRawGraph().getMetadata();

OSchema oSchema = oMetadata.getSchema();
OClass oRestricted = oSchema.getClass("ORestricted");

OrientVertexType v = orientGraphNoTx.getVertexBaseType();
v.addSuperClass(oRestricted);

OrientEdgeType e = orientGraphNoTx.getEdgeBaseType();
e.addSuperClass(oRestricted);

orientGraphNoTx.createVertexType(MEMORY_FACET);

orientGraphNoTx.shutdown();

System.out.println("DB " + DB_NAME + " has been created. Going to create security Context");

OrientGraph orientGraph = factory.getTx();

UUID contextUUID = UUID.randomUUID();
// Create Reader and Writers Roles and Users for Context identified by provided UUID
SecurityContext.createSecurityContext(orientGraph, contextUUID);
orientGraph.commit();
orientGraph.shutdown();

return contextUUID;
}

public OrientGraphFactory getFactory(UUID contextUUID){

String username = SecurityContext.getSecurityRoleOrUserName(
SecurityContext.PermissionMode.WRITER,
SecurityContext.SecurityType.USER, contextUUID);

String password = SecurityContext.WRITER_PASSWORD;

OrientGraphFactory factory = new OrientGraphFactory(HOST + "/" + DB_NAME,
username, password).setupPool(1, 10);
factory.setConnectionStrategy(OStorageRemote.CONNECTION_STRATEGY
.ROUND_ROBIN_CONNECT.toString());

return factory;
}

public void createVertex(OrientGraphFactory factory, UUID contextUUID){

System.out.println("Going to create " + MEMORY_FACET + " instance");

OrientGraph orientGraph = factory.getTx();

OrientVertex memory = orientGraph.addVertex("class:" + MEMORY_FACET);
SecurityContext.addToSecurityContext(orientGraph, memory, contextUUID);

List<ODocument> list = new ArrayList<>();
ODocument oDocument1 = new ODocument();
oDocument1 = oDocument1.fromJSON("{\"key1\":\"Value1\"}");
list.add(oDocument1);

ODocument oDocument2 = new ODocument();
oDocument2 = oDocument2.fromJSON("{\"key2\":\"Value2\"}");
list.add(oDocument2);
memory.setProperty("test", list, OType.EMBEDDEDLIST);
memory.save();

orientGraph.commit();
orientGraph.shutdown();
}


public void updateVertex(OrientGraphFactory factory, UUID contextUUID){
System.out.println("Going to update " + MEMORY_FACET + " instance.");

OrientGraph orientGraph = factory.getTx();
Iterable<Vertex> vertexes = orientGraph.getVerticesOfClass(MEMORY_FACET);

Vertex v = vertexes.iterator().next();

List<ODocument> list2 = new ArrayList<>();
ODocument oDocument3 = new ODocument();
oDocument3 = oDocument3.fromJSON("{\"key3\":\"Value3\"}");
list2.add(oDocument3);

ODocument oDocument4 = new ODocument();
oDocument4 = oDocument4.fromJSON("{\"key4\":\"Value4\"}");
list2.add(oDocument4);
((OrientVertex) v).setProperty("test", list2, OType.EMBEDDEDLIST);

orientGraph.commit();

System.out.println("Changes to " + MEMORY_FACET + " committed.");

orientGraph.shutdown();

}

public void execute() throws IOException {
UUID contextUUID = createDBTypesAndContext();
OrientGraphFactory factory = getFactory(contextUUID);
createVertex(factory, contextUUID);
updateVertex(factory, contextUUID);
System.out.println("DONE");
}

public static void main(String args[]) throws Exception {
ReproduceBug7354 reproduceBug7354 = new ReproduceBug7354();
reproduceBug7354.execute();
}

}
Loading

0 comments on commit 17e8a24

Please sign in to comment.