1 7 package org.jboss.test.cache.test.eviction; 8 9 import junit.framework.TestCase; 10 import junit.framework.Test; 11 import junit.framework.TestSuite; 12 import org.jboss.cache.Fqn; 13 import org.jboss.cache.eviction.RegionManager; 14 import org.jboss.cache.eviction.RegionNameConflictException; 15 import org.jboss.cache.eviction.Region; 16 17 import java.util.HashMap ; 18 19 22 public class RegionManagerUnitTestCase extends TestCase 23 { 24 private final String DEFAULT_REGION = "/_default_/"; 25 26 public RegionManagerUnitTestCase(String s) 27 { 28 super(s); 29 } 30 31 public void setUp() throws Exception 32 { 33 super.setUp(); 34 } 35 36 public void tearDown() throws Exception 37 { 38 super.tearDown(); 39 } 40 41 public void testCreateRegion() { 42 String fqn1 = "/a/b/c"; 43 String fqn2 = "/a/b"; 44 String fqn3 = "/aop"; 45 46 RegionManager regionManager = new RegionManager(null); 47 try { 48 regionManager.createRegion(DEFAULT_REGION, null); 49 regionManager.createRegion(fqn1, null); 50 regionManager.createRegion(fqn2, null); 51 regionManager.createRegion(fqn3, null); 52 } catch (RegionNameConflictException e) { 53 fail("Failed to create region"); 54 e.printStackTrace(); } 56 57 Region[] regions = regionManager.getRegions(); 58 assertEquals("Region size ", 4, regions.length); 59 } 60 61 public void testCreateRegion2() { 62 String fqn1 = "/a/b/c"; 63 String fqn2 = "/a/b/"; 64 65 RegionManager regionManager = new RegionManager(null); 66 try { 67 regionManager.createRegion(fqn1, null); 68 regionManager.createRegion(fqn2, null); 69 } catch (RegionNameConflictException e) { 70 fail("Failed to create region"); 71 e.printStackTrace(); } 73 74 Region[] regions = regionManager.getRegions(); 75 assertEquals("Region size ", 2, regions.length); 76 assertEquals("Region 0 ", "/a/b/", regions[0].getFqn()); 77 assertEquals("Region 1 ", "/a/b/c/", regions[1].getFqn()); 78 Region region = regionManager.getRegion("/a/b/c/d"); 79 assertNotNull("Region ", region); 80 assertEquals("Region ", "/a/b/c/", region.getFqn()); 81 region = regionManager.getRegion("/a/b"); 82 assertNotNull("Region ", region); 83 assertEquals("Region ", "/a/b/", region.getFqn()); 84 region = regionManager.getRegion("/a"); 85 assertNull("Region ", region); 86 } 87 88 public void testRegionConflict() { 89 String fqn1 = "/a/b"; 90 String fqn2 = "/a/b/c"; 91 String fqn3 = "/aop"; 92 93 RegionManager regionManager = new RegionManager(null); 94 try { 95 regionManager.createRegion(DEFAULT_REGION, null); 96 regionManager.createRegion(fqn1, null); 97 regionManager.createRegion(fqn2, null); 98 regionManager.createRegion(fqn3, null); 99 } catch (RegionNameConflictException e) { 100 Region[] regions = regionManager.getRegions(); 101 assertEquals("Region size ", 2, regions.length); 102 return; 103 } 104 fail("testRegionConflict failed"); 105 } 106 107 public void testRegionConflict2() { 108 String fqn1 = "/a/b/"; 109 String fqn2 = "/a/b/c/"; 110 String fqn3 = "/a/bc"; 111 112 RegionManager regionManager = new RegionManager(null); 113 try { 114 regionManager.createRegion(fqn1, null); 115 regionManager.createRegion(fqn2, null); 116 regionManager.createRegion(fqn3, null); 117 } catch (RegionNameConflictException e) { 118 Region[] regions = regionManager.getRegions(); 119 assertEquals("Region size ", 1, regions.length); 120 return; 121 } 122 fail("testRegionConflict failed"); 123 } 124 125 public void testGetRegion() { 126 String fqn1 = "/a/bc"; 127 String fqn2 = "/a/b"; 128 129 RegionManager regionManager = new RegionManager(null); 130 try { 131 regionManager.createRegion(fqn1, null); 132 } catch (RegionNameConflictException e) { 133 fail("testRegionConflict3 failed " +e); 134 } 135 136 Region region = regionManager.getRegion(fqn2); 137 assertNull("Region " , region); 138 } 139 140 void log(String msg) 141 { 142 System.out.println("-- " + msg); 143 } 144 145 public static Test suite() 146 { 147 return new TestSuite(RegionManagerUnitTestCase.class); 148 } 149 150 public static void main(String [] args) 151 { 152 junit.textui.TestRunner.run(suite()); 153 } 154 155 } 156 | Popular Tags |