@Test public void testPending() throws L2pSecurityException, EncodingFailedException, SerializationException, InterruptedException, AgentException { adam.unlockPrivateKey("adamspass"); eve.unlockPrivateKey("evespass"); LocalNode testee = LocalNode.launchAgent(adam); MessageResultListener l = new MessageResultListener(4000) { @Override public void notifySuccess() { LocalNodeTest.testVariable = true; } }; Message m = new Message(adam, eve, new PingPongContent()); testee.sendMessage(m, l); Thread.sleep(2000); assertFalse(testVariable); assertFalse(l.isSuccess()); assertFalse(l.isFinished()); // launch another node hosting eve LocalNode.launchAgent(eve); Thread.sleep(LocalNode.getMaxMessageWait() + 3000); assertTrue(l.isSuccess()); assertTrue(l.isFinished()); assertTrue(testVariable); }
@Test public void testTimeout() throws EncodingFailedException, L2pSecurityException, SerializationException, InterruptedException, AgentException { adam.unlockPrivateKey("adamspass"); LocalNode testee1 = LocalNode.launchAgent(adam); MessageResultListener l = new MessageResultListener(2000) { public void notifyTimeout() { LocalNodeTest.testVariable = true; } }; Message m = new Message(adam, eve, new PingPongContent(), 1000); LocalNode.setPendingTimeOut(1000); testee1.sendMessage(m, l); Thread.sleep(30000); assertFalse(l.isSuccess()); assertTrue(l.isTimedOut()); assertEquals(0, l.getResults().length); assertTrue(testVariable); }
private StructuredGraph parseAndProcess(String snippet) { StructuredGraph graph = parse(snippet); LocalNode local = graph.getNodes(LocalNode.class).first(); ConstantNode constant = ConstantNode.forInt(0, graph); for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) { n.replaceFirstInput(local, constant); } Map<Invoke, Double> hints = new HashMap<>(); for (Invoke invoke : graph.getInvokes()) { hints.put(invoke, 1000d); } Assumptions assumptions = new Assumptions(false); new InliningPhase( runtime(), hints, replacements, assumptions, null, getDefaultPhasePlan(), OptimisticOptimizations.ALL) .apply(graph); new CanonicalizerPhase.Instance(runtime(), assumptions, true).apply(graph); new DeadCodeEliminationPhase().apply(graph); return graph; }
@Override public void clear(Graph g, Configuration configuration) throws Exception { super.clear(g, configuration); if (node != null) { node.deleteIndices(); } }
public void testGetLocalNode() { System.setProperty("gov.nih.nci.ncia.grid.local.node.name", "disp1"); System.setProperty("local.grid.uri", "url"); NBIANode node = LocalNode.getLocalNode(); assertTrue(node.isLocal()); assertEquals(node.getDisplayName(), "disp1"); assertEquals(node.getURL(), "url"); }
@Test public void testUserRegistry() throws CryptoException, L2pSecurityException, AgentException { UserAgent a = UserAgent.createUserAgent("a"); UserAgent b = UserAgent.createUserAgent("b"); a.unlockPrivateKey("a"); b.unlockPrivateKey("b"); a.setLoginName("alpha"); b.setLoginName("beta"); LocalNode testee = LocalNode.launchNode(); testee.storeAgent(a); testee.storeAgent(b); assertEquals(a.getId(), testee.getAgentIdForLogin("alpha")); assertEquals(b.getId(), testee.getAgentIdForLogin("beta")); try { testee.getAgentIdForLogin("bla"); fail("AgentNotKnownException expected"); } catch (AgentNotKnownException e) { // corrects } }
@Test public void testSimpleInvokation() throws L2pSecurityException, CryptoException, AgentAlreadyRegisteredException, AgentException, SecurityException, IllegalArgumentException, AgentNotKnownException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InterruptedException { String serviceClass = "i5.las2peer.api.TestService"; ServiceAgent testService = ServiceAgent.generateNewAgent(serviceClass, "a passphrase"); testService.unlockPrivateKey("a passphrase"); LocalNode testee = LocalNode.launchNode(); eve.unlockPrivateKey("evespass"); testee.storeAgent(eve); eve.lockPrivateKey(); testee.storeAgent(testService); testee.registerReceiver(testService); Serializable result = testee.invokeLocally( eve.getId(), serviceClass, "inc", new Serializable[] {new Integer(10)}); assertEquals(12, result); }
@Test public void testRegisteringAgents() throws L2pSecurityException, MalformedXMLException, IOException, AgentAlreadyRegisteredException, AgentNotKnownException, AgentException { adam.unlockPrivateKey("adamspass"); // abel.unlockPrivateKey ( "abelspass"); LocalNode testee = LocalNode.launchAgent(adam); // testee.storeAgent(abel); try { testee.storeAgent(abel); fail("L2sSecurityAxception expected"); } catch (L2pSecurityException e) { } try { testee.storeAgent(adam); fail("AgentAlreadyRegistered exception expected"); } catch (AgentAlreadyRegisteredException e) { } abel.unlockPrivateKey("abelspass"); testee.storeAgent(abel); LocalNode testee2 = LocalNode.launchNode(); UserAgent retrieve = (UserAgent) testee2.getAgent(abel.getId()); assertTrue(retrieve.isLocked()); try { testee2.updateAgent(retrieve); fail("SecurtityException expected"); } catch (L2pSecurityException e) { } retrieve.unlockPrivateKey("abelspass"); testee2.updateAgent(retrieve); }
@Test public void testTwoNodes() throws L2pSecurityException, EncodingFailedException, SerializationException, InterruptedException, AgentException { adam.unlockPrivateKey("adamspass"); eve.unlockPrivateKey("evespass"); // launch to nodes with one agent each LocalNode testee1 = LocalNode.launchAgent(adam); LocalNode.launchAgent(eve); assertTrue(LocalNode.findAllNodesWithAgent(adam.getId()).length > 0); assertTrue(LocalNode.findAllNodesWithAgent(eve.getId()).length > 0); MessageResultListener l = new MessageResultListener(10000); Message m = new Message(adam, eve, new PingPongContent()); testee1.sendMessage(m, l); l.waitForAllAnswers(); assertEquals(1, l.getNumberOfExpectedResults()); assertTrue(l.isFinished()); assertTrue(l.isSuccess()); }
@Before public void setUp() throws NoSuchAlgorithmException, L2pSecurityException, CryptoException, MalformedXMLException, IOException { LocalNode.reset(); eve = MockAgentFactory.getEve(); adam = MockAgentFactory.getAdam(); abel = MockAgentFactory.getAbel(); counter = 0; testVariable = false; }
@Test public void test() throws AgentAlreadyRegisteredException, EncodingFailedException, L2pSecurityException, SerializationException, InterruptedException, AgentException, AgentNotKnownException { System.out.println("start: " + new Date()); LocalNode testee = LocalNode.launchNode(); try { testee.registerReceiver(eve); fail("L2pSecurityException expected"); } catch (L2pSecurityException e) { } eve.unlockPrivateKey("evespass"); adam.unlockPrivateKey("adamspass"); testee.registerReceiver(eve); testee.registerReceiver(adam); assertFalse(eve.isLocked()); assertFalse(adam.isLocked()); System.out.println("check1: " + new Date()); testVariable = false; MessageResultListener listener = new MessageResultListener(10000) { public void notifySuccess() { LocalNodeTest.testVariable = true; } }; PingPongContent c = new PingPongContent(); Message m = new Message(adam, eve, c); testee.sendMessage(m, listener); listener.waitForAllAnswers(); assertFalse(listener.isTimedOut()); assertFalse(listener.hasException()); assertTrue(listener.isSuccess()); assertTrue(listener.isFinished()); Message answer = listener.getResults()[0]; answer.open(adam, testee); assertTrue(c.getTimestamp() < ((PingPongContent) answer.getContent()).getTimestamp()); assertTrue(testVariable); }
@Test public void testUserRegDistribution() throws L2pSecurityException, AgentException, CryptoException, ArtifactNotFoundException { LocalNode testee1 = LocalNode.launchNode(); long id = Envelope.getClassEnvelopeId(UserAgentList.class, "mainlist"); for (int i = 0; i < 11; i++) { UserAgent a = UserAgent.createUserAgent("pass" + i); a.unlockPrivateKey("pass" + i); a.setLoginName("login_" + i); testee1.storeAgent(a); } // check, that the user list is stored testee1.fetchArtifact(id); LocalNode testee2 = LocalNode.launchNode(); // check, that the user list is stored testee2.fetchArtifact(id); testee2.getAgentIdForLogin("login_2"); }
@Test public void testStartupAgents() throws L2pSecurityException, AgentException { LocalNode testee = LocalNode.newNode(); testee.storeAgent(adam); testee.launch(); try { testee.storeAgent(abel); fail("L2pSecurityException expected"); } catch (L2pSecurityException e) { // ok } abel.unlockPrivateKey("abelspass"); testee.storeAgent(abel); }
/** * Resolve a constraint against an RDF/XML document. * * <p>Resolution is by filtration of a URL stream, and thus very slow. */ public Resolution resolve(Constraint constraint) throws QueryException { if (logger.isDebugEnabled()) { logger.debug("Resolve " + constraint); } // Validate "constraint" parameter if (constraint == null) { throw new IllegalArgumentException("Null \"constraint\" parameter"); } if (!(constraint.getModel() instanceof LocalNode)) { if (logger.isDebugEnabled()) logger.debug("Ignoring solutions for " + constraint); return new EmptyResolution(constraint, false); } if (!(constraint.getElement(1) instanceof LocalNode) || !(constraint.getElement(2) instanceof LocalNode)) { throw new QueryException( "Prefix resolver can only be used for fixed prefixes: " + constraint); } try { long property = ((LocalNode) constraint.getElement(1)).getValue(); LocalNode object = (LocalNode) constraint.getElement(2); Node prefixNode = resolverSession.globalize(object.getValue()); // check the constraint for consistency if ((property != mulgaraPrefix && property != mulgaraStringPrefix) || !(prefixNode instanceof Literal || prefixNode instanceof URIReference)) { logger.debug("property = " + property + ", mulgaraPrefix = " + mulgaraPrefix); logger.debug("element(2): " + prefixNode + " [" + prefixNode.getClass().getName() + "]"); throw new QueryException( "Prefix resolver can only be used for prefix constraints: " + constraint); } if (logger.isDebugEnabled()) { logger.debug( "Evaluating " + constraint.getElement(0) + " has prefix " + constraint.getElement(2)); } ConstraintElement node = constraint.getElement(0); assert node != null; Tuples tuples; if (node instanceof Variable) { // convert the prefix into a string pool object SPObjectFactory spoFact = SPObjectFactoryImpl.getInstance(); SPObject startPrefixObj = getStartObject(spoFact, prefixNode, property); SPObject endPrefixObj = getEndObject(spoFact, prefixNode, property); // get the extents of the prefix from the string pool tuples = resolverSession.findStringPoolRange(startPrefixObj, true, endPrefixObj, false); assert tuples != null; // rename variables away from subject, predicate and object tuples.renameVariables(constraint); long resultSize; try { // Get the size of the final result. resultSize = tuples.getRowCount(); } catch (TuplesException e) { throw new QueryException("Unable to build result", e); } if (logger.isDebugEnabled()) { try { logger.debug( "tuples size = " + tuples.getRowCount() + " (should be " + resultSize + ")"); } catch (TuplesException e) { logger.debug("Error getting the length of the tuples object"); } } return new TuplesWrapperResolution(tuples, constraint); } else { // if (node instanceof Variable) // node must therefore be an instanceof LocalNode // we can shortcut the process here assert node instanceof LocalNode; LocalNode n = (LocalNode) node; // get the node out of the string pool SPObject spo = resolverSession.findStringPoolObject(n.getValue()); // check that the node exists if (spo == null) { tuples = TuplesOperations.empty(); } else { // see if the node starts with the required prefix String prefix; // extract the string from the literal if (prefixNode instanceof Literal) { prefix = ((Literal) prefixNode).getLexicalForm(); } else { prefix = ((URIReference) prefixNode).getURI().toString(); } if (spo.getLexicalForm().startsWith(prefix)) { tuples = TuplesOperations.unconstrained(); } else { tuples = TuplesOperations.empty(); } } } // convert the tuples to a resolution return new TuplesWrapperResolution(tuples, constraint); } catch (GlobalizeException ge) { throw new QueryException("Couldn't convert internal data into a string", ge); } catch (StringPoolException e) { throw new QueryException("Couldn't query constraint", e); } }
@Test public void testBroadcast() throws EncodingFailedException, L2pSecurityException, SerializationException, InterruptedException, AgentException, AgentNotKnownException { adam.unlockPrivateKey("adamspass"); eve.unlockPrivateKey("evespass"); // launch three nodes with one agent each LocalNode testee1 = LocalNode.launchAgent(adam); LocalNode hosting1 = LocalNode.launchAgent(eve); assertEquals(1, LocalNode.findAllNodesWithAgent(eve.getId()).length); LocalNode hosting2 = LocalNode.launchAgent(eve); assertTrue(hosting1.hasLocalAgent(eve)); assertTrue(hosting2.hasLocalAgent(eve)); assertNotSame(hosting1.getAgent(eve.getId()), hosting2.getAgent(eve.getId())); assertEquals(2, LocalNode.findAllNodesWithAgent(eve.getId()).length); MessageResultListener l = new MessageResultListener(10000) { public void notifySuccess() { synchronized (this) { System.out.println("result retrieved"); LocalNodeTest.counter++; } } }; // l.addRecipient(); assertEquals(1, l.getNumberOfExpectedResults()); Message m = new Message(adam, eve, new PingPongContent()); testee1.sendMessage(m, l, Node.SendMode.BROADCAST); assertEquals(2, l.getNumberOfExpectedResults()); l.waitForAllAnswers(); assertEquals(2, l.getNumberOfResults()); assertEquals(counter, 2); assertTrue(l.isSuccess()); assertTrue(l.isFinished()); }
public Client getClient() { return node.getClient(); }
@Override public void loadGraphData( Graph graph, LoadGraphWith loadGraphWith, Class testClass, String testName) { super.loadGraphData(graph, loadGraphWith, testClass, testName); node.getClient().admin().indices().prepareRefresh().get(); }