Package org.apache.jcs

Examples of org.apache.jcs.JCS


  @Test
  public void testCacheInitSystemProperty() throws Throwable {
    System.setProperty(CRUtil.PORTALNODE_CONFPATH, confPath.getPath());
    EnvironmentConfiguration.loadCacheProperties();
    JCS instance = JCS.getInstance("test");
    assertNotNull("Cannot initialize the JCS cache from the given config: " + confPath, instance);
    assertEquals("The cache attributes are not loaded from the given config", 314, instance.getCacheAttributes()
        .getMaxObjects());
  }
View Full Code Here


  @Test
  public void testCacheInitWithConfigSetted() throws Throwable {
    EnvironmentConfiguration.setCacheFilePath(confPath.getPath() + File.separator + "cache2.ccf");
    EnvironmentConfiguration.loadCacheProperties();
    JCS instance = JCS.getInstance("test");
    assertNotNull("Cannot initialize the JCS cache from the given config: " + confPath, instance);
    assertEquals("The cache attributes are not loaded from the given config", 315, instance.getCacheAttributes()
        .getMaxObjects());
  }
View Full Code Here

  /**
   * Init the JCS Cache.
   * @return initialized cache
   */
  private static JCS initCache() {
    JCS cache = null;
    try {

      cache = JCS.getInstance(IMAGE_CACHE_REGION);
      log.debug("Using cache zone " + IMAGE_CACHE_REGION + " for image resizing");
    } catch (final CacheException e) {
View Full Code Here

    if (!frameParsed) {
      String framePath = config.getString(FRAME_KEY);
      String framePlaceholder = config.getString(FRAMEPLACEHOLDER_KEY);
      if (framePath != null && !framePath.equals("") && framePlaceholder != null && !framePlaceholder.equals("")) {
        try {
          JCS cache = JCS.getInstance(VelocityContentRepository.class.getSimpleName() + ".famecache");
          footer = (String) cache.get(framePath + FOOTER_CACHE_KEY_SUFFIX);
          header = (String) cache.get(framePath + HEADER_CACHE_KEY_SUFFIX);
          if (header == null || footer == null) {
            URL frameURL = new URL(framePath);
            URLConnection conn = frameURL.openConnection();
            Object content = conn.getContent();
            if (content instanceof InputStream) {
              header = StringUtils.readUntil((InputStream) content, framePlaceholder);
              footer = StringUtils.streamToString((InputStream) content);
            } else {
              logger.error(
                "Error reading frame source" + framePath,
                new CRException("Unknown response type (" + content.getClass() + ")"));
            }
            cache.put(framePath + HEADER_CACHE_KEY_SUFFIX, header);
            cache.put(framePath + FOOTER_CACHE_KEY_SUFFIX, footer);

          }
        } catch (MalformedURLException e) {
          logger.error("Error reading frame source " + framePath, e);
        } catch (IOException e) {
View Full Code Here

     *@exception  Exception  Description of the Exception
     */
    public void testSimpleLoad()
        throws Exception
    {
        JCS jcs = JCS.getInstance( "testCache1" );
//        ICompositeCacheAttributes cattr = jcs.getCacheAttributes();
//        cattr.setMaxObjects( 20002 );
//        jcs.setCacheAttributes( cattr );

        for ( int i = 0; i <= items; i++ )
        {
            jcs.put( i + ":key", "data" + i );
        }

        for ( int i = items; i >= items; i-- )
        {
            String res = ( String ) jcs.get( i + ":key" );
            if ( res == null )
            {
                this.assertNotNull( "[" + i + ":key] should not be null", res );
            }
        }

        // test removal
        jcs.destroy( "300:key" );
        assertNull( jcs.get( "300:key" ) );

    }
View Full Code Here

        junit.textui.TestRunner.main( testCaseName );
    }

    public void testJCS() throws Exception
    {
        JCS jcs = JCS.getInstance( "testCache1" );
       
        LinkedList list = buildList();
       
        jcs.put( "some:key", list );
       
        assertEquals( list, jcs.get( "some:key" ) );
    }
View Full Code Here

    public void testSpoolEvent()
        throws Exception
    {
        MyEventHandler meh = new MyEventHandler();

        JCS jcs = JCS.getInstance( "WithDisk" );
        // this should add the event handler to all items as they are created.
        IElementAttributes attributes = jcs.getDefaultElementAttributes();
        attributes.addElementEventHandler( meh );
        jcs.setDefaultElementAttributes( attributes );

        // put them in
        for ( int i = 0; i <= items; i++ )
        {
            jcs.put( i + ":key", "data" + i );
        }

        // wait a bit for it to finish
        Thread.sleep( items / 20 );
View Full Code Here

     * @throws Exception
     */
    public void testSpoolNoDiskEvent()
        throws Exception
    {
        JCS jcs = JCS.getInstance( "NoDisk" );

        MyEventHandler meh = new MyEventHandler();

        // this should add the event handler to all items as they are created.
        IElementAttributes attributes = jcs.getDefaultElementAttributes();
        attributes.addElementEventHandler( meh );
        jcs.setDefaultElementAttributes( attributes );

        // put them in
        for ( int i = 0; i <= items; i++ )
        {
            jcs.put( i + ":key", "data" + i );
        }

        // wait a bit for it to finish
        Thread.sleep( items / 20 );

View Full Code Here

     *                If an error occurs
     */
    public void runTestForRegionInRange( String region, int start, int end )
        throws Exception
    {
        JCS jcs = JCS.getInstance( region );

        // Add items to cache
        for ( int i = start; i <= end; i++ )
        {
            jcs.put( i + ":key", region + " data " + i );
        }

        // Test that all items are in cache
        for ( int i = start; i <= end; i++ )
        {
            String value = (String) jcs.get( i + ":key" );

            assertEquals( region + " data " + i, value );
        }

        // Remove all the items
        for ( int i = start; i <= end; i++ )
        {
            jcs.remove( i + ":key" );
        }

        System.out.println( jcs.getStats() );

        // Verify removal
        // another thread may have inserted since
        for ( int i = start; i <= end; i++ )
        {
            assertNull( "Removed key should be null: " + i + ":key " + "\n stats " + jcs.getStats(), jcs.get( i
                + ":key" ) );
        }
    }
View Full Code Here

    public void testSpoolNotAllowedEvent()
        throws Exception
    {
        MyEventHandler meh = new MyEventHandler();

        JCS jcs = JCS.getInstance( "DiskButNotAllowed" );
        // this should add the event handler to all items as they are created.
        IElementAttributes attributes = jcs.getDefaultElementAttributes();
        attributes.addElementEventHandler( meh );
        jcs.setDefaultElementAttributes( attributes );

        // put them in
        for ( int i = 0; i <= items; i++ )
        {
            jcs.put( i + ":key", "data" + i );
        }

        // wait a bit for it to finish
        Thread.sleep( items / 20 );
View Full Code Here

TOP

Related Classes of org.apache.jcs.JCS

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.