Package nexj.core.runtime

Examples of nexj.core.runtime.InvocationContext


    * externally.
    */
   public void testOptimisticLockingUpdateFail() throws Exception
   {
      Metadata metadata = loadMetadata("filestorage");
      InvocationContext context = new InvocationContext(metadata);

      try
      {
         /* ***** Configure the data source connection with temporary directories ***** */
         File mainDir = TempFileUtil.makeTemporaryDirectory(getName());
         File tempDir = new File(mainDir, "temp");
         File dataDir = new File(mainDir, "data");
         File jrnlDir = new File(mainDir, "journal");
        
         assertTrue(tempDir.mkdir());
         assertTrue(dataDir.mkdir());
         assertTrue(jrnlDir.mkdir());
        
        
         DataSource ds = metadata.getDataSource("TestFilePersistenceDataSource");
        
         assertEquals(1, ds.getFragmentCount());
        
         FileDataSourceFragment defaultFrag = (FileDataSourceFragment)ds.getDefaultFragment();
        
         defaultFrag.debugSettings(dataDir.getAbsolutePath(),
            tempDir.getAbsolutePath(),
            jrnlDir.getAbsolutePath());
        
         //Write a data file
         File dataFile = new File(dataDir, "u_" + SysUtil.FILE_SEP + "__" + SysUtil.FILE_SEP + "__" + SysUtil.FILE_SEP + "u");
        
         assertTrue(dataFile.getParentFile().mkdirs());

         Writer writer = IOUtil.openBufferedWriter(dataFile, XMLUtil.ENCODING);

         writer.write("Original contents");
         writer.close();
        
         long lOriginalModified = dataFile.lastModified();
        
         //Now try to do a query.
         assertNull(context.beginTransaction());
        
         Metaclass testFPA = metadata.getMetaclass("TestFPA");
         Object where = parse("(= (@ id) \"u\")");
         Query query = Query.createRead(testFPA, null, where, null, 10, 0, false, Query.SEC_NONE, context);
        
         InstanceList resultList = query.read();
        
         assertEquals(1, resultList.size());
        
         Instance result = resultList.getInstance(0);
        
         assertEquals(new Binary("Original contents".getBytes("utf-8")), result.getValue("data"));
        
         result.setValue("data", new Binary("Modified through adapter.".getBytes("utf-8")));
        
         //Edit the data file outside the adapter
         writer = IOUtil.openBufferedWriter(dataFile, XMLUtil.ENCODING);
         writer.write("Modified directly.");
         writer.close();
         dataFile.setLastModified(lOriginalModified + 1);
        
         //Try to commit
         try
         {
            commit(context);
            fail("Expected OptimisticLockException");
         }
         catch (OptimisticLockException ex)
         {
            assertEquals("TestFPA", ex.getClassName());
         }
        
         context.getUnitOfWork().rollback(true);
        
         assertNull(context.beginTransaction());
        
         //Re-read
         result.invoke("read", new Object[]{
            parse("(data)"),
            parse("(= (@ id) \"u\")"), null, null, null, null
         });
         assertEquals(new Binary("Modified directly.".getBytes("utf-8")), result.getValue("data"));
      }
      finally
      {
         context.complete(false);
         ThreadContextHolder.setContext(null);
      }
   }
View Full Code Here


    * externally.
    */
   public void testOptimisticLockingDeleteFail() throws Exception
   {
      Metadata metadata = loadMetadata("filestorage");
      InvocationContext context = new InvocationContext(metadata);
     
      try
      {
         /* ***** Configure the data source connection with temporary directories ***** */
         File mainDir = TempFileUtil.makeTemporaryDirectory(getName());
         File tempDir = new File(mainDir, "temp");
         File dataDir = new File(mainDir, "data");
         File jrnlDir = new File(mainDir, "journal");
        
         assertTrue(tempDir.mkdir());
         assertTrue(dataDir.mkdir());
         assertTrue(jrnlDir.mkdir());
        
        
         DataSource ds = metadata.getDataSource("TestFilePersistenceDataSource");
        
         assertEquals(1, ds.getFragmentCount());
        
         FileDataSourceFragment defaultFrag = (FileDataSourceFragment)ds.getDefaultFragment();
        
         defaultFrag.debugSettings(dataDir.getAbsolutePath(),
            tempDir.getAbsolutePath(),
            jrnlDir.getAbsolutePath());
        
         //Write a data file
         File dataFile = new File(dataDir, "d_" + SysUtil.FILE_SEP + "__" + SysUtil.FILE_SEP + "__" + SysUtil.FILE_SEP + "d");
        
         assertTrue(dataFile.getParentFile().mkdirs());
        
         Writer writer = IOUtil.openBufferedWriter(dataFile, XMLUtil.ENCODING);
        
         writer.write("Original contents");
         writer.close();
        
         long lOriginalModified = dataFile.lastModified();
        
         //Now try to do a query.
         assertNull(context.beginTransaction());
        
         Metaclass testFPA = metadata.getMetaclass("TestFPA");
         Object where = parse("(= (@ id) \"d\")");
         Query query = Query.createRead(testFPA, null, where, null, 10, 0, false, Query.SEC_NONE, context);
        
         InstanceList resultList = query.read();
        
         assertEquals(1, resultList.size());
        
         Instance result = resultList.getInstance(0);
        
         assertEquals(new Binary("Original contents".getBytes("utf-8")), result.getValue("data"));
        
         //DELETE it
         result.invoke("delete");
        
         //Edit the data file outside the adapter
         writer = IOUtil.openBufferedWriter(dataFile, XMLUtil.ENCODING);
         writer.write("Modified directly.");
         writer.close();
         dataFile.setLastModified(lOriginalModified + 1);
        
         //Try to commit
         try
         {
            commit(context);
            fail("Expected OptimisticLockException");
         }
         catch (OptimisticLockException ex)
         {
            assertEquals("TestFPA", ex.getClassName());
         }
        
         context.getUnitOfWork().rollback(true);
        
         assertNull(context.beginTransaction());
        
         //Re-read
         result.invoke("read", new Object[]{
            parse("(data)"),
            parse("(= (@ id) \"d\")"), null, null, null, null
         });

         assertEquals(new Binary("Modified directly.".getBytes("utf-8")), result.getValue("data"));
      }
      finally
      {
         context.complete(false);
         ThreadContextHolder.setContext(null);
      }
   }
View Full Code Here

    * with the file persistence adapter.
    */
   public void testFragmentReplicationUpdateDelete() throws Exception
   {
      Metadata metadata = loadMetadata("filestoragefragment");
      InvocationContext context = new InvocationContext(metadata);
     
      try
      {
         ThreadContextHolder.setContext(context);
     
         File mainDir = TempFileUtil.makeTemporaryDirectory(getName());
         File tempDir = new File(mainDir, "temp");
         File dataDir = new File(mainDir, "data");
         File jrnlDir = new File(mainDir, "journal");
        
         File tempDir1 = new File(mainDir, "temp1");
         File dataDir1 = new File(mainDir, "data1");
         File jrnlDir1 = new File(mainDir, "journal1");
        
         assertTrue(tempDir.mkdir());
         assertTrue(dataDir.mkdir());
         assertTrue(jrnlDir.mkdir());
        
         assertTrue(tempDir1.mkdir());
         assertTrue(dataDir1.mkdir());
         assertTrue(jrnlDir1.mkdir());
        
         DataSource ds = metadata.getDataSource("TestFilePersistenceDataSource");
        
         assertEquals(2, ds.getFragmentCount());
        
         FileDataSourceFragment defaultFrag = (FileDataSourceFragment)ds.getDefaultFragment();
         FileDataSourceFragment fragment1 = (FileDataSourceFragment)ds.getFragment("fragment1");
        
         defaultFrag.debugSettings(dataDir.getAbsolutePath(),
            tempDir.getAbsolutePath(),
            jrnlDir.getAbsolutePath());
        
         fragment1.debugSettings(dataDir1.getAbsolutePath(),
            tempDir1.getAbsolutePath(),
            jrnlDir1.getAbsolutePath());
        
         // Create it
         assertNull(context.beginTransaction());
        
         Metaclass testFPA = metadata.getMetaclass("TestFPA");
         Instance a = (Instance)testFPA.invoke("new");
        
         a.setValue("data", new Binary("Creation (\u4e2d\u6587) data.".getBytes("utf-8")));
        
         // Replicate
         context.getUnitOfWork().addReplicationFragment(a, "fragment1");
        
         commit(context);
  
         OID oidA = a.getOID();
         String sOidName = (String)oidA.getValue(0);
        
         // Verify
         File defaultFile = FileManagedConnection.splitNameToSubdirs(dataDir, sOidName, 3, 2, false);
        
         assertTrue(defaultFile.exists());
         assertEquals("Creation (\u4e2d\u6587) data.", readFileToString(defaultFile));
        
         File fragment1File = FileManagedConnection.splitNameToSubdirs(dataDir1, sOidName, 3, 2, false);
        
         assertTrue(fragment1File.exists());
         assertEquals("Creation (\u4e2d\u6587) data.", readFileToString(fragment1File));
        
         // Update it
         assertNull(context.beginTransaction());
        
         a.setValue("data", new Binary("Modified data.\nModified.".getBytes("utf-8")));
        
         // Replication
         context.getUnitOfWork().addReplicationFragment(a, "fragment1");
        
         commit(context);
        
         // Verify
         assertTrue(defaultFile.exists());
         assertEquals("Modified data.\nModified.", readFileToString(defaultFile));
         assertTrue(fragment1File.exists());
         assertEquals("Modified data.\nModified.", readFileToString(fragment1File));
        
         // Delete it
         assertNull(context.beginTransaction());
        
         a.invoke("delete");
        
         // Replication
         context.getUnitOfWork().addReplicationFragment(a, "fragment1");
        
         commit(context);
        
         //Verify
         assertFalse(defaultFile.exists());
         assertFalse(fragment1File.exists());
      }
      finally
      {
         context.complete(false);
         ThreadContextHolder.setContext(null);
      }
   }
View Full Code Here

    * @return The lock was aquired.
    */
   public boolean lock()
   {
      // reinitialize member variables for every call (same as setUp() did before)
      m_context = new InvocationContext(getMetadata());
      m_database = (RelationalDatabase)getMetadata().getDataSource(getDataSourceName());
      m_adapter = (SQLAdapter)m_database.getComponent().getInstance(m_context);

      // hints declared/used by core/test/nexj/base/upgrades/Main.upgrade, need for dropSchema()
      RelationalSchemaTest.addHint((RelationalSchema)m_database.getSchema(), "test1");
View Full Code Here

   protected void setUp() throws Exception
   {
      super.setUp();

      m_metadata = Repository.getMetadata();
      m_context = new InvocationContext(m_metadata);

      try
      {
         m_context.initialize(null);
         m_context.getMachine().eval(
View Full Code Here

      m_exception = e;

      m_soapFault = new SOAPFault(m_exception);

      m_marshaller = new XMLMarshaller(new InvocationContext(Repository.getMetadata()),
                                       Repository.getMetadata());
      m_unmarshaller = new XMLUnmarshaller(new InvocationContext(Repository.getMetadata()),
                                           Repository.getMetadata());
     
      m_writer = new StringWriter();
   }
View Full Code Here

   }

   public void testBasicResponse() throws IOException
   {
      StringWriter writer = new StringWriter();
      XMLUnmarshaller unmarshaller = new XMLUnmarshaller(new InvocationContext(Repository.getMetadata()));
      Response response = new Response();
      TransferObject tobj = new TransferObject("User");

      tobj.setValue("e", new Double(2.71828183));
      tobj.setValue("privilegeSet", new Integer(42));
View Full Code Here

   }

   public void testDynamicChangeResponse() throws MarshallerException, IOException
   {
      StringWriter writer = new StringWriter();
      XMLUnmarshaller unmarshaller = new XMLUnmarshaller(new InvocationContext(Repository.getMetadata()));
      StringReader reader = new StringReader("<Change-Request xmlns=\"" + XML.NS_URI_TNS
         + "\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><objects x" + "si:type=\"Principal\"><"
         + XML.BASE_PREFIX + "oid>10e8359492f25f4be49109b9979e684ff3</" + XML.BASE_PREFIX
         + "oid><" + XML.BASE_PREFIX + "event>welcome</" + XML.BASE_PREFIX
         + "event><name>fullname</name></objects><attributes>(firstName name)</attributes></Change-Request>");
View Full Code Here

   }

   public void testDynamicReadResponse() throws MarshallerException, IOException
   {
      StringWriter writer = new StringWriter();
      XMLUnmarshaller unmarshaller = new XMLUnmarshaller(new InvocationContext(Repository.getMetadata()));
      StringReader reader = new StringReader("<Read-Request xmlns=\"" + XML.NS_URI_TNS + "\"><class>Principal</class>"
         + "<attributes>(fullName name)</attributes><where></where><orderBy></orderBy><count>8</count>"
         + "<offset>0</offset></Read-Request>");
      Response response = new Response();
      TransferObject tobj = new TransferObject("User");
View Full Code Here

   }

   public void testDynamicRestrictedChangeResponse() throws MarshallerException, IOException
   {
      StringWriter writer = new StringWriter();
      XMLUnmarshaller unmarshaller = new XMLUnmarshaller(new InvocationContext(Repository.getMetadata()));
      StringReader reader = new StringReader("<Principal-Change-Request xmlns=\"" + XML.NS_URI_TNS + "\"><objects><"
         + XML.BASE_PREFIX + "oid>10e8359492f25f4be49109b9979e684ff3</" + XML.BASE_PREFIX
         + "oid><" + XML.BASE_PREFIX + "event>welcome</" + XML.BASE_PREFIX
         + "event><name>fullname</name></objects><attributes>(fullName name)</attributes></Principal-Change-Request>");
      Response response = new Response();
View Full Code Here

TOP

Related Classes of nexj.core.runtime.InvocationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.