Ejemplo n.º 1
0
 def setUpClass(cls):
     super(BaseTestCase, cls).setUpClass()
     setup('localhost', concurrency='eventlet')
Ejemplo n.º 2
0
from mogwai import connection, properties
from mogwai.models import Vertex, Edge
from mogwai.tools import SessionPoolManager, PartitionGraph
import eventlet

connection.setup("localhost", concurrency="eventlet")

##
#  Persist a session with SessionPoolManager
##


def isolation_test(scope):
    wrapper_config = {"bindings": {"scope": scope}, "pool_size": 5}
    scope_values = []

    with SessionPoolManager(**wrapper_config) as pool:
        for i in range(7):
            scope_val = connection.execute_query("scope *= 2", isolate=False, pool=pool)
            scope_values.append(scope_val)

    return scope, scope_values


pile = eventlet.GreenPile()
[pile.spawn(isolation_test, i) for i in range(10)]

for scope, scope_values in pile:
    assert scope_values == [scope * 2 ** i for i in range(1, 8)]

Ejemplo n.º 3
0
from bottle import Bottle, run, request, response, abort, redirect, jinja2_view as view, static_file
from bottle_memcache import MemcachePlugin
from mogwai.connection import setup, execute_query
from models import *
from tools import groupCountToObjValueMap

setup('localhost', concurrency='eventlet')

app = Bottle()
mc_plugin = MemcachePlugin(servers=['localhost:11211', ])
app.install(mc_plugin)


@app.error(404)
def error404(error):
    return "Nothing here."


@app.route('/static/<path:path>')
def callback(path):
    path = path.replace('../', '').strip(';')
    return static_file(path, 'views/static/')


@app.get('/', apply=[view('index')])
def index(mc):
    counts = mc.get('index_counts')
    if not counts:
        user_count = User.count()
        occupation_count = Occupation.count()
        movie_count = Movie.count()
Ejemplo n.º 4
0
from mogwai import connection, properties
from mogwai.models import Vertex, Edge
from mogwai.tools import SessionPoolManager, BlueprintsWrapper, PartitionGraph
from mogwai.exceptions import MogwaiGremlinException

connection.setup('localhost')

##
#  Persist a session with SessionPoolManager
##

k = 10

with SessionPoolManager(bindings={'k': k}):
    gsk = connection.execute_query('"powers of ${k}"')
    pysk = "powers of {}".format(k)
    assert gsk == pysk

    kk = connection.execute_query("k * k")
    assert kk == k * k


##
#  Wrap the graph with a Blueprints Implementation
##

class BlueprintsWrapperVertex(Vertex):
    element_type = 'blueprints_wrapper_vertex'
    name = properties.String(required=True, max_length=128)

Ejemplo n.º 5
0
 def setUpClass(cls):
     super(TestWrapperConcurrency, cls).setUpClass()
     host_params = connection.HOST_PARAMS.copy()
     host_params.pop('port')
     connection.setup(concurrency='eventlet', **host_params)
Ejemplo n.º 6
0
 def tearDownClass(cls):
     host_params = connection.HOST_PARAMS.copy()
     host_params.pop('port')
     connection.setup(concurrency='sync', **host_params)
     super(TestWrapperConcurrency, cls).tearDownClass()
Ejemplo n.º 7
0
from mogwai.connection import setup
from mogwai.models import Vertex, Edge
from mogwai import properties
from mogwai import gremlin
from mogwai._compat import print_
import datetime
from pytz import utc
from functools import partial
import os

setup("127.0.0.1")


class IsFriendsWith(Edge):
    label = "is_friends_with"

    since = properties.DateTime(
        required=True, default=partial(datetime.datetime.now, tz=utc), description="Owned object since"
    )


class Person(Vertex):

    element_type = "person"  # this is optional, will default to the class name
    gremlin_path = os.path.join(os.getcwd(), "custom_gremlin.groovy")

    name = properties.String(required=True, max_length=512)
    email = properties.Email(required=True)

    friends_and_friends_of_friends = gremlin.GremlinMethod(
        method_name="friends_and_friends_of_friends",
Ejemplo n.º 8
0
 def setUpClass(cls):
     super(TestWrapperConcurrency, cls).setUpClass()
     host_params = connection.HOST_PARAMS.copy()
     host_params.pop('port')
     connection.setup(concurrency='eventlet', **host_params)
Ejemplo n.º 9
0
from mogwai import connection, properties
from mogwai.models import Vertex, Edge
from mogwai.tools import SessionPoolManager, PartitionGraph
import eventlet

connection.setup('localhost', concurrency='eventlet')

##
#  Persist a session with SessionPoolManager
##


def isolation_test(scope):
    wrapper_config = {'bindings': {'scope': scope}, 'pool_size': 5}
    scope_values = []

    with SessionPoolManager(**wrapper_config) as pool:
        for i in range(7):
            scope_val = connection.execute_query("scope *= 2",
                                                 isolate=False,
                                                 pool=pool)
            scope_values.append(scope_val)

    return scope, scope_values


pile = eventlet.GreenPile()
[pile.spawn(isolation_test, i) for i in range(10)]

for scope, scope_values in pile:
    assert scope_values == [scope * 2**i for i in range(1, 8)]
Ejemplo n.º 10
0
from mogwai.connection import setup
from mogwai.models import Vertex
from mogwai import properties
from mogwai.gremlin import GremlinMethod

setup('127.0.0.1')


class Trinket(Vertex):

    element_type = 'gadget'

    name = properties.String(required=True, max_length=1024)

    test_method = GremlinMethod(path='example_groovy_imports.groovy', method_name='test_method',
                                imports=['com.thinkaurelius.titan.core.util.*'], classmethod=True)

# Call the test method:
result1, result2 = Trinket.test_method(1, 2)
assert result1 == 1
assert result2 == 2
Ejemplo n.º 11
0
from mogwai.connection import setup, execute_query
from mogwai.models import Vertex, Edge
from mogwai import properties, relationships
import datetime
from pytz import utc
from functools import partial
from mogwai._compat import print_

import xlrd
import simplejson as json

setup('192.168.0.140')

class Data(Vertex):
    element_type = "data"

wb = xlrd.open_workbook('/Users/dharni/Downloads/WA_Energy_Weather_Use_Case_Datasets/EU_EnergyPocketbook2014_Exploration_Layout.xls')
sh = wb.sheet_by_index(0)

values = []

for row_index in xrange(1, sh.nrows):
    for col_index in xrange(sh.ncols):
        values.insert(col_index, sh.cell(row_index, col_index).value)
    #Data.create(col_1=values[0],col_2=values[1],col_3=values[2],col_4=values[3],col_5=values[4],col_6=values[5],col_7=values[6])

results = Data.find_by_value("col_5","Belgium",False)

print_(type(results))
print_(len(results))
Ejemplo n.º 12
0
if not args.password:
    args.password = ''
if not args.database:
    args.database = 'graph'

hd = connection._parse_host(args.host, args.username, args.password,
                            args.database)
host = hd.get('host', 'localhost')
port = hd.get('port', 8184)
username = hd.get('username', '')
password = hd.get('password', '')
graph_name = hd.get('graph_name', 'graph')

connection.setup([
    host,
],
                 graph_name=graph_name,
                 username=username,
                 password=password)

del args, parser, username, password, hd


class __help_object(object):
    def __repr__(self):
        return """The following have already been imported:
  - mogwai.connection as connection
  - mogwai.models as models
  - mogwai.properties as properties
  - mogwai.gremlin as gremlin
  - mogwai.exceptions as exceptions"""
Ejemplo n.º 13
0
 def tearDownClass(cls):
     host_params = connection.HOST_PARAMS.copy()
     host_params.pop('port')
     connection.setup(concurrency='sync', **host_params)
     super(TestWrapperConcurrency, cls).tearDownClass()
Ejemplo n.º 14
0
from mogwai.connection import setup
from mogwai.models import Vertex, Edge
from mogwai import properties
from mogwai import relationships
from mogwai._compat import print_
import datetime
from pytz import utc
from functools import partial
import pickle

setup('127.0.0.1')


class OwnsObject(Edge):

    label = 'owns_object'  # this is optional, will default to the class name

    since = properties.DateTime(required=True,
                                default=partial(datetime.datetime.now, tz=utc),
                                description='Owned object since')


class Trinket(Vertex):

    element_type = 'gadget'

    name = properties.String(required=True, max_length=1024)


class Person(Vertex):
Ejemplo n.º 15
0
from unittest import TestCase

from mogwai.connection import setup

from model import DataFactory

setup('192.168.1.107')


class TestDataFactory(TestCase):
    def setUp(self):
        self.dataFactory = DataFactory()

    def tearDown(self):
        self.dataFactory.despose()
        self.dataFactory = None

    def test_create(self):
        data = 'user'
        details = {'name': 'test', 'age': '20'}

        self.dataFactory.create(data, details)

        self.fail()

    def test_delete(self):
        self.fail()
Ejemplo n.º 16
0
 def setUpClass(cls):
     super(BaseMogwaiTestCase, cls).setUpClass()
     #sync_spec(filename='test.spec', host='192.168.133.12', graph_name='graph')
     setup(os.getenv('TITAN_REXPRO_URL', 'localhost'), graph_name='graph')
Ejemplo n.º 17
0
from mogwai import connection, properties
from mogwai.models import Vertex, Edge
from mogwai.tools import SessionPoolManager, BlueprintsWrapper, PartitionGraph
from mogwai.exceptions import MogwaiGremlinException

connection.setup('localhost')

##
#  Persist a session with SessionPoolManager
##

k = 10

with SessionPoolManager(bindings={'k': k}):
    gsk = connection.execute_query('"powers of ${k}"')
    pysk = "powers of {}".format(k)
    assert gsk == pysk

    kk = connection.execute_query("k * k")
    assert kk == k * k

##
#  Wrap the graph with a Blueprints Implementation
##


class BlueprintsWrapperVertex(Vertex):
    element_type = 'blueprints_wrapper_vertex'
    name = properties.String(required=True, max_length=128)