def test_cells_ensure_subscribed(self): schema = Schema("core.web.test2") @schema.define class Thing2: k = Indexed(int) x = int computed = threading.Event() def checkThing2s(): ensureSubscribedType(Thing2) res = Sequence([ Span("Thing(k=%s).x = %s" % (thing.k, thing.x)) for thing in Thing2.lookupAll() ]) computed.set() return res self.cells.withRoot(Subscribed(checkThing2s)) self.cells.renderMessages() self.assertTrue(computed.wait(timeout=5.0))
def main(argv): parser = argparse.ArgumentParser("Run a database throughput test") parser.add_argument("host") parser.add_argument("port") parser.add_argument("--service-token", type=str, required=True, help="the auth token to be used with this service") parser.add_argument("seconds", type=float) parser.add_argument("--threads", dest='threads', type=int, default=1) parsedArgs = parser.parse_args(argv[1:]) db = connect(parsedArgs.host, parsedArgs.port, parsedArgs.service_token) schema = Schema("database_throughput_test") @schema.define class Counter: k = int db.subscribeToSchema(schema) t0 = time.time() transactionCount = [] def doWork(): with db.transaction(): c = Counter() while time.time() - t0 < parsedArgs.seconds: with db.transaction(): c.k = c.k + 1 with db.view(): transactionCount.append(c.k) threads = [ threading.Thread(target=doWork) for _ in range(parsedArgs.threads) ] for t in threads: t.start() for t in threads: t.join() print( sum(transactionCount) / parsedArgs.seconds, " transactions per second") return 0
import os import traceback import threading import time import object_database from object_database.web import cells as cells from object_database.service_manager.ServiceSchema import service_schema from object_database.service_manager.ServiceBase import ServiceBase from object_database.service_manager.Codebase import Codebase from object_database import Schema, Indexed, Index, core_schema, SubscribeLazilyByDefault from object_database.view import revisionConflictRetry from typed_python import OneOf, Alternative, ConstDict, TupleOf task_schema = Schema("core.task") #how many times our worker can disconnect in a row before we get marked 'Failed' MAX_TIMES_FAILED = 10 @task_schema.define class ResourceScope: pass class TaskContext(object): """Placeholder for information about the current running task environment passed into tasks.""" def __init__(self, db, storageRoot, codebase): self.db = db self.storageRoot = storageRoot
Traceback, ) from object_database import InMemServer, Schema, Indexed, connect from object_database.util import genToken, configureLogging from object_database.test_util import (currentMemUsageMb, autoconfigure_and_start_service_manager, log_cells_stats) from py_w3c.validators.html.validator import HTMLValidator import logging import unittest import threading test_schema = Schema("core.web.test") @test_schema.define class Thing: k = Indexed(int) x = int class CellsHTMLTests(unittest.TestCase): @classmethod def setUpClass(cls): configureLogging(preamble="cells_html_test", level=logging.INFO) cls._logger = logging.getLogger(__name__) def setUp(self):
import time import sys import io import pydoc from typed_python import python_ast, OneOf, Alternative, TupleOf,\ NamedTuple, Tuple, Class, ConstDict, Member import datetime import ast from object_database import Schema, Indexed, current_transaction BUTTON_COLOR = "#999999" SELECTED_PROJECT_COLOR = "#EEEEFF" SELECTED_MODULE_COLOR = "lightblue" nyc = pytz.timezone("America/New_York") schema = Schema("research_app.ResearchFrontend") class CodeSelection(NamedTuple(start_row = int, start_column = int, end_row = int, end_column = int)): @staticmethod def fromAceEditorJson(selection): return CodeSelection( start_row = selection["start"]["row"], start_column = selection["start"]["column"], end_row = selection["end"]["row"], end_column = selection["end"]["column"] ) def slice(self, buffer):
import numpy import argparse import logging import types import time import sys import io import pydoc import research_app.Displayable as Displayable from typed_python import python_ast, OneOf, Alternative, TupleOf,\ NamedTuple, Tuple, Class, ConstDict, Member, ListOf import datetime import ast from object_database import Schema, Indexed, current_transaction schema = Schema("research_app.ResearchBackend") @schema.define class ServiceConfig: pass Error = NamedTuple(error=str, line=int, trace = str) CodeBlock = NamedTuple(code=str, line_range=Tuple(int,int)) class ResearchBackend(ServiceBase): def initialize(self, chunkStoreOverride=None): self._logger = logging.getLogger(__file__) self.db.subscribeToSchema(schema) self.db.subscribeToSchema(ContentSchema.schema)
"""A simple 'codebase' for testing purposes""" from object_database.service_manager.ServiceBase import ServiceBase from object_database.service_manager.Task import TaskExecutor, RunningTask, TaskStatusResult from object_database import Schema import time schema = Schema("TestModule1") @schema.define class Record: x = int def createNewRecord(db): db.subscribeToNone(Record) with db.transaction(): Record(x=10) class RunningTaskWithSubtasks(RunningTask): """A slow, simple task that runs for 1/20th of a second, and that fires off some subtasks. We use this for testing a task graph with dependencies. """ def __init__(self, x): self.x = x def execute(self, taskContext, subtaskResults): if subtaskResults is None: time.sleep(0.05)
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ Content-management schema for the research frontend. """ import time from typed_python import OneOf from object_database import Schema, Indexed, current_transaction schema = Schema("research_app.ContentSchema") @schema.define class ModuleContents: # gives the prior script in edit-time - if we navigate to an old script and edit it, # that older script will be the parent. parent = OneOf(None, schema.ModuleContents) timestamp = float # actual contents of the script contents = str @schema.define class Project: name = Indexed(str)
from object_database.service_manager.ServiceManagerTestCommon import ServiceManagerTestCommon from object_database.service_manager.ServiceManager import ServiceManager from object_database.service_manager.ServiceBase import ServiceBase import object_database.service_manager.ServiceInstance as ServiceInstance from object_database.util import genToken from object_database.test_util import autoconfigure_and_start_service_manager from object_database import ( Schema, Indexed, core_schema, connect, service_schema, current_transaction ) ownDir = os.path.dirname(os.path.abspath(__file__)) ownName = os.path.basename(os.path.abspath(__file__)) schema = Schema("core.ServiceManagerTest") @schema.define class TestServiceCounter: k = int @schema.define class PointsToShow: timestamp = float y = float @schema.define class Feigenbaum:
# Coyright 2017-2019 Nativepython Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from object_database import Schema service_schema = Schema("core.service")
# Copyright 2019 Nativepython Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.from collections import defaultdict from object_database import Schema active_webservice_schema = Schema("core.active_webservice")
# limitations under the License. import boto3 import datetime import logging import os import time import traceback import uuid from typed_python import OneOf, ConstDict from object_database import ServiceBase, Schema, Indexed from object_database.web import cells from object_database.util import closest_N_in schema = Schema("core.AwsWorkerBootService") valid_instance_types = { 'm1.small': { 'RAM': 1.7, 'CPU': 1, 'COST': 0.044 }, 'm1.medium': { 'RAM': 3.75, 'CPU': 1, 'COST': 0.087 }, 'm1.large': { 'RAM': 7.5, 'CPU': 2,
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ schema for the evaluation state of the research frontend. """ import time from typed_python import OneOf, TupleOf from object_database import Schema, Indexed, current_transaction from research_app.ContentSchema import Module from research_app.Displayable import Display schema = Schema("research_app.EvaluationSchema") @schema.define class EvaluationContext: """A place to store evaluation outputs""" module = OneOf(None, Module) displaySnippet = OneOf( None, str) # the snippet to display, or None for the whole thing state = OneOf( "Empty", # the module hasn't been set yet via 'request' "Dirty", # client wants us to compute "Calculating", # the engine is calculating "Complete" # the calculation is complete )
from object_database.service_manager.ServiceBase import ServiceBase import object_database.service_manager.ServiceInstance as ServiceInstance from object_database.web.cells import (Button, SubscribedSequence, Subscribed, Text, Dropdown, Card, Plot, Code, Slot, CodeEditor, Columns, Tabs, Grid, Sheet, ensureSubscribedType, SubscribeAndRetry, Expands, AsyncDropdown, ButtonGroup, Octicon) from object_database import (Schema, Indexed, core_schema, Index, service_schema, current_transaction) ownDir = os.path.dirname(os.path.abspath(__file__)) ownName = os.path.basename(os.path.abspath(__file__)) schema = Schema("core.ServiceManagerTest") @schema.define class TestServiceCounter: k = int @schema.define class PointsToShow: timestamp = float y = float @schema.define class Feigenbaum: