Store { public void initialise(final String graphId, final Schema schema, final StoreProperties properties) throws StoreException { LOGGER.debug("Initialising {}", getClass().getSimpleName()); if (null == graphId) { throw new IllegalArgumentException("graphId is required"); } this.graphId = graphId; this.schema = schema; setProperties(properties); updateJsonSerialiser(); startCacheServiceLoader(properties); this.jobTracker = createJobTracker(); optimiseSchema(); validateSchemas(); addOpHandlers(); addExecutorService(properties); if (properties.getJobTrackerEnabled() && !jobsRescheduled) { try (final CloseableIterable<JobDetail> scheduledJobs = this.jobTracker.getAllScheduledJobs()) { if (scheduledJobs != null) { StreamSupport.stream(scheduledJobs.spliterator(), false) .peek(jd -> LOGGER.debug("Rescheduling job: {}", jd)) .forEach(this::rescheduleJob); } } jobsRescheduled = true; } } Store();  Store(final Boolean addCoreOpHandlers); static Store createStore(final String graphId, final byte[] schema, final Properties storeProperties); static Store createStore(final String graphId, final Schema schema, final StoreProperties storeProperties); void initialise(final String graphId, final Schema schema, final StoreProperties properties); static void updateJsonSerialiser(final StoreProperties storeProperties); void updateJsonSerialiser(); boolean hasTrait(final StoreTrait storeTrait); abstract Set<StoreTrait> getTraits(); void execute(final Operation operation, final Context context); O execute(final Output<O> operation, final Context context); JobDetail executeJob(final Operation operation, final Context context); JobDetail executeJob(final Job job, final Context context); void runAsync(final Runnable runnable); JobTracker getJobTracker(); boolean isSupported(final Class<? extends Operation> operationClass); Set<Class<? extends Operation>> getSupportedOperations(); Set<Class<? extends Operation>> getNextOperations(final Class<? extends Operation> operation); @SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT", justification = "Getters are called to trigger the loading data") Element populateElement(final Element lazyElement); String getGraphId(); Schema getSchema(); StoreProperties getProperties(); GraphLibrary getGraphLibrary(); void setGraphLibrary(final GraphLibrary library); void optimiseSchema(); void validateSchemas(); Context createContext(final User user); OperationChainValidator getOperationChainValidator(); void addOperationChainOptimisers(final List<OperationChainOptimiser> newOpChainOptimisers); void addOperationHandler(final Class<? extends Operation> opClass, final OperationHandler handler); void addOperationHandler(final Class<? extends Output<O>> opClass, final OutputOperationHandler<OP, O> handler); OperationHandler<Operation> getOperationHandler(final Class<? extends Operation> opClass); Object handleOperation(final Operation operation, final Context context); void setOriginalSchema(final Schema originalSchema); Schema getOriginalSchema();  }
@Test public void shouldThrowExceptionIfGraphIdIsNull() throws Exception { final StoreProperties properties = mock(StoreProperties.class); given(properties.getJobExecutorThreadCount()).willReturn(1); try { store.initialise(null, schema, properties); fail("Exception expected"); } catch (final IllegalArgumentException e) { assertNotNull(e.getMessage()); } }
@Test public void shouldThrowExceptionWhenPropertyIsNotSerialisable() throws StoreException { final Schema mySchema = new Schema.Builder() .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .property(TestPropertyNames.PROP_1, "invalidType") .build()) .type("invalidType", new TypeDefinition.Builder() .clazz(Object.class) .serialiser(new StringSerialiser()) .build()) .build(); final StoreProperties properties = mock(StoreProperties.class); given(properties.getJobExecutorThreadCount()).willReturn(1); try { store.initialise("graphId", mySchema, properties); fail(); } catch (final SchemaException exception) { assertNotNull(exception.getMessage()); } }
@Test public void shouldUpdateJsonSerialiser() throws StoreException { final StoreProperties properties = mock(StoreProperties.class); given(properties.getJsonSerialiserClass()).willReturn(TestCustomJsonSerialiser1.class.getName()); given(properties.getJsonSerialiserModules()).willReturn(StorePropertiesTest.TestCustomJsonModules1.class.getName()); given(properties.getJobExecutorThreadCount()).willReturn(1); TestCustomJsonSerialiser1.mapper = mock(ObjectMapper.class); System.setProperty(JSONSerialiser.JSON_SERIALISER_CLASS_KEY, TestCustomJsonSerialiser1.class.getName()); StorePropertiesTest.TestCustomJsonModules1.modules = Arrays.asList( mock(Module.class), mock(Module.class) ); final Store store = new StoreImpl(); final Schema schema = new Schema(); store.initialise("graphId", schema, properties); assertEquals(TestCustomJsonSerialiser1.class, JSONSerialiser.getInstance().getClass()); assertSame(TestCustomJsonSerialiser1.mapper, JSONSerialiser.getMapper()); verify(TestCustomJsonSerialiser1.mapper, times(2)).registerModules(StorePropertiesTest.TestCustomJsonModules1.modules); }
@Test public void shouldFindInvalidSerialiser() throws Exception { final Class<StringToStringSerialiser> invalidSerialiserClass = StringToStringSerialiser.class; Schema invalidSchema = new Schema.Builder() .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .source("string") .destination("invalidString") .directed("true") .property(TestPropertyNames.PROP_1, "string") .property(TestPropertyNames.PROP_2, "string") .build()) .type("string", new TypeDefinition.Builder() .clazz(String.class) .serialiser(new StringSerialiser()) .build()) .type("invalidString", new TypeDefinition.Builder() .clazz(String.class) .serialiser(invalidSerialiserClass.newInstance()) .build()) .type("true", Boolean.class) .build(); final StoreProperties properties = mock(StoreProperties.class); given(properties.getJobExecutorThreadCount()).willReturn(1); final Class<ToBytesSerialiser> validSerialiserInterface = ToBytesSerialiser.class; try { new StoreImpl() { @Override protected Class<? extends Serialiser> getRequiredParentSerialiserClass() { return validSerialiserInterface; } }.initialise("graphId", invalidSchema, properties); fail("Should have thrown exception"); } catch (final SchemaException e) { assertTrue(e.getMessage().contains(invalidSerialiserClass.getSimpleName())); } }