Author: dain Date: Fri Oct 29 23:13:43 2004 New Revision: 56028 Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalConfigStore.java geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/log/HOWLLog.java Log: GBean persistence actually works now Changed HOWL log to divide the buffer size by 1024 on get because HOWL is not symmentrical
Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java ============================================================================== --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java (original) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java Fri Oct 29 23:13:43 2004 @@ -320,6 +320,7 @@ public Object getPersistentValue() { if (!persistent) { + throw new IllegalStateException("Attribute is not persistent " + getDescription()); } if (getInvoker != null && gmbean.getTarget() != null) { try { Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java ============================================================================== --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java (original) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java Fri Oct 29 23:13:43 2004 @@ -35,6 +35,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Collections; import javax.management.AttributeNotFoundException; import javax.management.JMRuntimeException; import javax.management.ObjectName; @@ -97,7 +98,7 @@ private final ConfigurationParent parent; private final List classPath; private final List dependencies; - private final byte[] gbeanState; + private byte[] gbeanState; private final Collection repositories; private final ConfigurationStore configurationStore; @@ -105,7 +106,6 @@ private Map gbeans; private ClassLoader classLoader; - private byte[] savedState; /** * Constructor that can be used to create an offline Configuration, typically @@ -128,8 +128,16 @@ this.parentID = parentID; this.parent = parent; this.gbeanState = gbeanState; - this.classPath = classPath; - this.dependencies = dependencies; + if (classPath == null) { + this.classPath = Collections.EMPTY_LIST; + } else { + this.classPath = classPath; + } + if (dependencies == null) { + this.dependencies = Collections.EMPTY_LIST; + } else { + this.dependencies = dependencies; + } this.repositories = repositories; this.configurationStore = configurationStore; } @@ -245,7 +253,7 @@ // save state try { - savedState = storeGBeans(gbeans); + gbeanState = storeGBeans(gbeans); } catch (InvalidConfigException e) { log.info(e); } @@ -305,12 +313,12 @@ this.baseURL = baseURL; } - public ClassLoader getClassLoader() { - return classLoader; + public byte[] getGbeanState() { + return gbeanState; } - public byte[] getSavedState() { - return savedState; + public ClassLoader getClassLoader() { + return classLoader; } private static class ConfigInputStream extends ObjectInputStream { Modified: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalConfigStore.java ============================================================================== --- geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalConfigStore.java (original) +++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalConfigStore.java Fri Oct 29 23:13:43 2004 @@ -100,7 +100,11 @@ public void doStart() throws WaitingException, FileNotFoundException, IOException { // resolve the root dir if not alredy resolved if (rootDir == null) { - rootDir = new File(serverInfo.resolve(root)); + if (serverInfo == null) { + rootDir = new File(root); + } else { + rootDir = new File(serverInfo.resolve(root)); + } if (!rootDir.isDirectory()) { throw new FileNotFoundException("Store root does not exist or is not a directory: " + rootDir); } Modified: geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java ============================================================================== --- geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java (original) +++ geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java Fri Oct 29 23:13:43 2004 @@ -23,12 +23,19 @@ import java.io.ObjectOutputStream; import java.net.URI; import java.net.URL; +import java.util.HashMap; +import java.util.Map; import java.util.jar.JarOutputStream; import java.util.zip.ZipEntry; +import javax.management.ObjectName; import junit.framework.TestCase; +import org.apache.geronimo.gbean.GBeanData; import org.apache.geronimo.gbean.jmx.GBeanMBean; +import org.apache.geronimo.kernel.Kernel; import org.apache.geronimo.kernel.config.Configuration; +import org.apache.geronimo.kernel.config.ConfigurationManager; +import org.apache.geronimo.kernel.management.State; /** * @@ -37,44 +44,104 @@ */ public class LocalConfigStoreTest extends TestCase { private File root; - private LocalConfigStore store; private URL source; private File sourceFile; private URI uri; + private Kernel kernel; + private byte[] state; + private ObjectName gbeanName1; + private ObjectName storeName; public void testInstall() throws Exception { - store.install(source); + kernel.invoke(storeName, "install", new Object[] {source}, new String[] {"java.net.URL"}); assertTrue(new File(root, "1/META-INF/config.ser").exists()); - assertEquals(new File(root, "1").toURL(), store.getBaseURL(uri)); - GBeanMBean config = store.getConfiguration(uri); + assertEquals(new File(root, "1").toURL(), + kernel.invoke(storeName, "getBaseURL", new Object[] {uri}, new String[] {"java.net.URI"})); + + GBeanMBean config = (GBeanMBean) kernel.invoke(storeName, "getConfiguration", new Object[] {uri}, new String[] {"java.net.URI"}); assertEquals(uri, config.getAttribute("ID")); } public void testReInstall() throws Exception { - store.install(source); - store.install(source); + kernel.invoke(storeName, "install", new Object[] {source}, new String[] {"java.net.URL"}); + kernel.invoke(storeName, "install", new Object[] {source}, new String[] {"java.net.URL"}); assertTrue(new File(root, "2/META-INF/config.ser").exists()); - store.install(source); + kernel.invoke(storeName, "install", new Object[] {source}, new String[] {"java.net.URL"}); assertTrue(new File(root, "3/META-INF/config.ser").exists()); - store.install(source); + kernel.invoke(storeName, "install", new Object[] {source}, new String[] {"java.net.URL"}); assertTrue(new File(root, "4/META-INF/config.ser").exists()); - store.install(source); + kernel.invoke(storeName, "install", new Object[] {source}, new String[] {"java.net.URL"}); assertTrue(new File(root, "5/META-INF/config.ser").exists()); - store.install(source); + kernel.invoke(storeName, "install", new Object[] {source}, new String[] {"java.net.URL"}); assertTrue(new File(root, "6/META-INF/config.ser").exists()); } + public void testUpdateConfig() throws Exception { + // install the config + kernel.invoke(storeName, "install", new Object[] {source}, new String[] {"java.net.URL"}); + + // load and start the config + ConfigurationManager configurationManager = kernel.getConfigurationManager(); + ObjectName configName = configurationManager.load(uri); + kernel.invoke(configName, "startRecursive", null, null); + + // make sure the config and the gbean are running + assertEquals(new Integer(State.RUNNING_INDEX), kernel.getAttribute(configName, "state")); + assertEquals(new Integer(State.RUNNING_INDEX), kernel.getAttribute(gbeanName1, "state")); + + // set the value + kernel.setAttribute(gbeanName1, "value", "9900990099"); + assertEquals("9900990099", kernel.getAttribute(gbeanName1, "value")); + + // stop and unload the config + kernel.stopGBean(configName); + configurationManager.unload(configName); + + // assure it was unloaded + assertFalse(kernel.isLoaded(configName)); + + // now reload and restart the config + configName = configurationManager.load(uri); + kernel.invoke(configName, "startRecursive", null, null); + + // make sure the value was reloaded correctly + assertEquals("9900990099", kernel.getAttribute(gbeanName1, "value")); + + // stop and unload the config + kernel.stopGBean(configName); + configurationManager.unload(configName); + } + protected void setUp() throws Exception { try { + kernel = new Kernel("test.kernel", "geronimo"); + kernel.boot(); + + gbeanName1 = new ObjectName("geronimo.test:name=MyMockGMBean1"); + GBeanMBean mockBean1 = new GBeanMBean(MockGBean.getGBeanInfo()); + mockBean1.setAttribute("value", "1234"); + + Map gbeans = new HashMap(); + gbeans.put(gbeanName1, mockBean1); + state = Configuration.storeGBeans(gbeans); + root = new File(System.getProperty("java.io.tmpdir") + "/config-store"); + recursiveDelete(root); root.mkdir(); - store = new LocalConfigStore(root); - store.doStart(); + storeName = new ObjectName("geronimo.test:role=ConfigurationStore,name=LocalConfigStore"); + GBeanData store = new GBeanData(LocalConfigStore.getGBeanInfo()); + store.setAttribute("root", root.toURI()); + + kernel.loadGBean(storeName, store, getClass().getClassLoader()); + kernel.startGBean(storeName); GBeanMBean gbean = new GBeanMBean(Configuration.GBEAN_INFO); uri = new URI("test"); gbean.setAttribute("ID", uri); + gbean.setAttribute("gBeanState", state); + + sourceFile = File.createTempFile("test", ".car"); source = sourceFile.toURL(); JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(sourceFile))); @@ -96,9 +163,8 @@ if (sourceFile != null) { sourceFile.delete(); } - store.doStop(); - store = null; recursiveDelete(root); + kernel.shutdown(); } private static void recursiveDelete(File root) throws Exception { Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/log/HOWLLog.java ============================================================================== --- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/log/HOWLLog.java (original) +++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transaction/log/HOWLLog.java Fri Oct 29 23:13:43 2004 @@ -141,7 +141,7 @@ } public int getBufferSizeKBytes() { - return configuration.getBufferSize(); + return configuration.getBufferSize()/1024; } public void setBufferSizeKBytes(int bufferSize) throws LogConfigurationException {