1 5 package com.tc.config.schema.setup; 6 7 import com.tc.config.schema.SettableConfigItem; 8 import com.tc.object.config.schema.AutoLock; 9 import com.tc.object.config.schema.Lock; 10 import com.tc.object.config.schema.LockLevel; 11 import com.tc.test.TCTestCase; 12 import com.tc.util.Assert; 13 import com.terracottatech.config.Autolock; 14 import com.terracottatech.config.Locks; 15 import com.terracottatech.config.NamedLock; 16 17 import java.io.File ; 18 19 23 public class TestTVSConfigurationSetupManagerFactoryTest extends TCTestCase { 24 25 private TestTVSConfigurationSetupManagerFactory factory; 26 private L2TVSConfigurationSetupManager l2Manager; 27 private L1TVSConfigurationSetupManager l1Manager; 28 29 public void setUp() throws Exception { 30 this.factory = new TestTVSConfigurationSetupManagerFactory( 31 TestTVSConfigurationSetupManagerFactory.MODE_DISTRIBUTED_CONFIG, 32 null, new FatalIllegalConfigurationChangeHandler()); 33 34 ((SettableConfigItem) this.factory.l2CommonConfig().logsPath()).setValue(getTempFile("l2-logs").toString()); 35 ((SettableConfigItem) this.factory.l1CommonConfig().logsPath()).setValue(getTempFile("l1-logs").toString()); 36 37 this.l2Manager = this.factory.createL2TVSConfigurationSetupManager(null); 38 this.l1Manager = this.factory.createL1TVSConfigurationSetupManager(); 39 } 40 41 public void testSettingValues() throws Exception { 42 ((SettableConfigItem) factory.dsoApplicationConfig().transientFields()).setValue(new String [] { "Foo.foo", 44 "Bar.bar" }); 45 46 ((SettableConfigItem) factory.l2DSOConfig().garbageCollectionInterval()).setValue(142); 48 ((SettableConfigItem) factory.l1CommonConfig().logsPath()).setValue("whatever"); 49 ((SettableConfigItem) factory.l2CommonConfig().dataPath()).setValue("marph"); 50 51 ((SettableConfigItem) factory.dsoApplicationConfig().locks()).setValue(createLocks(new Lock[] { 53 new AutoLock("Foo.foo(..)", LockLevel.CONCURRENT), 54 new com.tc.object.config.schema.NamedLock("bar", "Baz.baz(..)", LockLevel.READ) })); 55 56 ((SettableConfigItem) factory.l1DSOConfig().instrumentationLoggingOptions().logDistributedMethods()).setValue(true); 58 59 this.factory.activateConfigurationChange(); 60 61 System.err.println(this.l2Manager 62 .dsoApplicationConfigFor(TVSConfigurationSetupManagerFactory.DEFAULT_APPLICATION_NAME)); 63 System.err.println(this.l2Manager.systemConfig()); 64 System.err.println(this.l1Manager.dsoL1Config()); 65 66 assertEqualsOrdered(new String [] { "Foo.foo", "Bar.bar" }, this.l2Manager 67 .dsoApplicationConfigFor(TVSConfigurationSetupManagerFactory.DEFAULT_APPLICATION_NAME).transientFields() 68 .getObject()); 69 assertEquals(142, this.l2Manager.dsoL2Config().garbageCollectionInterval().getInt()); 70 assertEquals(new File ("whatever"), this.l1Manager.commonL1Config().logsPath().getFile()); 71 assertEquals(new File ("marph"), this.l2Manager.commonl2Config().dataPath().getFile()); 72 assertEqualsUnordered(new Lock[] { new AutoLock("Foo.foo(..)", LockLevel.CONCURRENT), 73 new com.tc.object.config.schema.NamedLock("bar", "Baz.baz(..)", LockLevel.READ) }, this.l2Manager 74 .dsoApplicationConfigFor(TVSConfigurationSetupManagerFactory.DEFAULT_APPLICATION_NAME).locks().getObject()); 75 assertTrue(this.l1Manager.dsoL1Config().instrumentationLoggingOptions().logDistributedMethods().getBoolean()); 76 } 77 78 private com.terracottatech.config.LockLevel.Enum level(LockLevel in) { 79 if (in.equals(LockLevel.CONCURRENT)) return com.terracottatech.config.LockLevel.CONCURRENT; 80 if (in.equals(LockLevel.READ)) return com.terracottatech.config.LockLevel.READ; 81 if (in.equals(LockLevel.WRITE)) return com.terracottatech.config.LockLevel.WRITE; 82 if (in.equals(LockLevel.SYNCHRONOUS_WRITE)) return com.terracottatech.config.LockLevel.SYNCHRONOUS_WRITE; 83 throw Assert.failure("Unknown lock level " + in); 84 } 85 86 private Locks createLocks(Lock[] locks) { 87 Locks out = Locks.Factory.newInstance(); 88 for (int i = 0; i < locks.length; ++i) { 89 if (locks[i].isAutoLock()) { 90 Autolock lock = out.addNewAutolock(); 91 lock.setLockLevel(level(locks[i].lockLevel())); 92 lock.setMethodExpression(locks[i].methodExpression()); 93 } else { 94 NamedLock lock = out.addNewNamedLock(); 95 lock.setLockLevel(level(locks[i].lockLevel())); 96 lock.setMethodExpression(locks[i].methodExpression()); 97 lock.setLockName(locks[i].lockName()); 98 } 99 } 100 return out; 101 } 102 103 } 104 | Popular Tags |