brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [53/72] [abbrv] incubator-brooklyn git commit: BROOKLYN-162 - jclouds last few package prefixes needed, and tidy in core and elsewhere related (or observed in the process)
Date Wed, 19 Aug 2015 11:10:11 GMT
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/InMemoryObjectStore.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/InMemoryObjectStore.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/InMemoryObjectStore.java
new file mode 100644
index 0000000..c842fd1
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/InMemoryObjectStore.java
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.mgmt.persist;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
+import org.apache.brooklyn.core.mgmt.persist.PersistMode;
+import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore;
+import org.apache.brooklyn.core.mgmt.persist.StoreObjectAccessorLocking;
+import org.apache.brooklyn.util.collections.MutableList;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Objects;
+
+public class InMemoryObjectStore implements PersistenceObjectStore {
+
+    private static final Logger log = LoggerFactory.getLogger(InMemoryObjectStore.class);
+
+    final Map<String,String> filesByName;
+    final Map<String, Date> fileModTimesByName;
+    boolean prepared = false;
+    
+    public InMemoryObjectStore() {
+        this(MutableMap.<String,String>of(), MutableMap.<String,Date>of());
+    }
+    
+    public InMemoryObjectStore(Map<String,String> map, Map<String, Date> fileModTimesByName) {
+        filesByName = map;
+        this.fileModTimesByName = fileModTimesByName;
+        log.debug("Using memory-based objectStore");
+    }
+    
+    @Override
+    public String getSummaryName() {
+        return "in-memory (test) persistence store";
+    }
+    
+    @Override
+    public void prepareForMasterUse() {
+    }
+
+    @Override
+    public void createSubPath(String subPath) {
+    }
+
+    @Override
+    public StoreObjectAccessor newAccessor(final String path) {
+        if (!prepared) throw new IllegalStateException("prepare method not yet invoked: "+this);
+        return new StoreObjectAccessorLocking(new SingleThreadedInMemoryStoreObjectAccessor(filesByName, fileModTimesByName, path));
+    }
+    
+    public static class SingleThreadedInMemoryStoreObjectAccessor implements StoreObjectAccessor {
+        private final Map<String, String> map;
+        private final Map<String, Date> mapModTime;
+        private final String key;
+
+        public SingleThreadedInMemoryStoreObjectAccessor(Map<String,String> map, Map<String, Date> mapModTime, String key) {
+            this.map = map;
+            this.mapModTime = mapModTime;
+            this.key = key;
+        }
+        @Override
+        public String get() {
+            synchronized (map) {
+                return map.get(key);
+            }
+        }
+        @Override
+        public byte[] getBytes() {
+            return get().getBytes();
+        }
+        @Override
+        public boolean exists() {
+            synchronized (map) {
+                return map.containsKey(key);
+            }
+        }
+        @Override
+        public void put(String val) {
+            synchronized (map) {
+                map.put(key, val);
+                mapModTime.put(key, new Date());
+            }
+        }
+        @Override
+        public void append(String val) {
+            synchronized (map) {
+                String val2 = get();
+                if (val2==null) val2 = val;
+                else val2 = val2 + val;
+
+                map.put(key, val2);
+                mapModTime.put(key, new Date());
+            }
+        }
+        @Override
+        public void delete() {
+            synchronized (map) {
+                map.remove(key);
+                mapModTime.remove(key);
+            }
+        }
+        @Override
+        public Date getLastModifiedDate() {
+            synchronized (map) {
+                return mapModTime.get(key);
+            }
+        }
+    }
+
+    @Override
+    public List<String> listContentsWithSubPath(final String parentSubPath) {
+        if (!prepared) throw new IllegalStateException("prepare method not yet invoked: "+this);
+        synchronized (filesByName) {
+            List<String> result = MutableList.of();
+            for (String file: filesByName.keySet())
+                if (file.startsWith(parentSubPath))
+                    result.add(file);
+            return result;
+        }
+    }
+
+    @Override
+    public void close() {
+    }
+
+    @Override
+    public String toString() {
+        return Objects.toStringHelper(this).add("size", filesByName.size()).toString();
+    }
+
+    @Override
+    public void injectManagementContext(ManagementContext mgmt) {
+    }
+    
+    @Override
+    public void prepareForSharedUse(PersistMode persistMode, HighAvailabilityMode haMode) {
+        prepared = true;
+    }
+
+    @Override
+    public void deleteCompletely() {
+        synchronized (filesByName) {
+            filesByName.clear();
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/InMemoryStoreObjectAccessorWriterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/InMemoryStoreObjectAccessorWriterTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/InMemoryStoreObjectAccessorWriterTest.java
new file mode 100644
index 0000000..47d401d
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/InMemoryStoreObjectAccessorWriterTest.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.mgmt.persist;
+
+import java.io.IOException;
+
+import org.apache.brooklyn.core.mgmt.persist.StoreObjectAccessorLocking;
+import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore.StoreObjectAccessorWithLock;
+import org.testng.annotations.Test;
+
+@Test
+public class InMemoryStoreObjectAccessorWriterTest extends PersistenceStoreObjectAccessorWriterTestFixture {
+
+    protected StoreObjectAccessorWithLock newPersistenceStoreObjectAccessor() throws IOException {
+        InMemoryObjectStore store = new InMemoryObjectStore();
+        store.prepareForSharedUse(null, null);
+        return new StoreObjectAccessorLocking(store.newAccessor("foo"));
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/ListeningObjectStore.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/ListeningObjectStore.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/ListeningObjectStore.java
new file mode 100644
index 0000000..c27011e
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/ListeningObjectStore.java
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.mgmt.persist;
+
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
+import org.apache.brooklyn.core.mgmt.persist.PersistMode;
+import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore;
+import org.apache.brooklyn.util.collections.MutableList;
+import org.apache.brooklyn.util.text.Strings;
+import org.apache.brooklyn.util.time.CountdownTimer;
+import org.apache.brooklyn.util.time.Duration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+public class ListeningObjectStore implements PersistenceObjectStore {
+
+    protected final PersistenceObjectStore delegate;
+    protected final List<ObjectStoreTransactionListener> listeners = MutableList.of();
+    private boolean writesFailSilently = false;
+
+    public static interface ObjectStoreTransactionListener {
+        public void recordQueryOut(String summary, int size);
+        public void recordDataOut(String summary, int size);
+        public void recordDataIn(String summary, int size);
+    }
+    
+    public static class RecordingTransactionListener implements ObjectStoreTransactionListener {
+        private static final Logger log = LoggerFactory.getLogger(ListeningObjectStore.RecordingTransactionListener.class);
+        
+        protected final String prefix;
+        protected final AtomicLong bytesIn = new AtomicLong();
+        protected final AtomicLong bytesOut = new AtomicLong();
+        protected final AtomicInteger countQueriesOut = new AtomicInteger();
+        protected final AtomicInteger countDataOut = new AtomicInteger();
+        protected final AtomicInteger countDataIn = new AtomicInteger();
+        
+        public RecordingTransactionListener(String prefix) {
+            this.prefix = prefix;
+        }
+        
+        public long getBytesIn() {
+            return bytesIn.get();
+        }
+        
+        public long getBytesOut() {
+            return bytesOut.get();
+        }
+        
+        public int getCountQueriesOut() {
+            return countQueriesOut.get();
+        }
+        
+        public int getCountDataOut() {
+            return countDataOut.get();
+        }
+        
+        public int getCountDataIn() {
+            return countDataIn.get();
+        }
+        
+        public String getTotalString() {
+            return "totals: out="+Strings.makeSizeString(bytesOut.get())+" in="+Strings.makeSizeString(bytesIn.get());
+        }
+        
+        @Override
+        public void recordQueryOut(String summary, int size) {
+            synchronized (this) { this.notifyAll(); }
+            bytesOut.addAndGet(size);
+            countQueriesOut.incrementAndGet();
+            log.info(prefix+" "+summary+" -->"+size+"; "+getTotalString());
+        }
+        
+        @Override
+        public void recordDataOut(String summary, int size) {
+            synchronized (this) { this.notifyAll(); }
+            bytesOut.addAndGet(size);
+            countDataOut.incrementAndGet();
+            log.info(prefix+" "+summary+" -->"+size+"; "+getTotalString());
+        }
+        
+        @Override
+        public void recordDataIn(String summary, int size) {
+            synchronized (this) { this.notifyAll(); }
+            bytesIn.addAndGet(size);
+            countDataIn.incrementAndGet();
+            log.info(prefix+" "+summary+" <--"+size+"; "+getTotalString());
+        }
+
+        public void blockUntilDataWrittenExceeds(long count, Duration timeout) throws InterruptedException, TimeoutException {
+            CountdownTimer timer = CountdownTimer.newInstanceStarted(timeout);
+            synchronized (this) {
+                while (bytesOut.get()<count) {
+                    if (timer.isExpired())
+                        throw new TimeoutException();
+                    timer.waitOnForExpiry(this);
+                }
+            }
+        }
+    }
+
+    public ListeningObjectStore(PersistenceObjectStore delegate, ObjectStoreTransactionListener ...listeners) {
+        this.delegate = Preconditions.checkNotNull(delegate);
+        for (ObjectStoreTransactionListener listener: listeners)
+            this.listeners.add(listener);
+    }
+
+    @Override
+    public String getSummaryName() {
+        return delegate.getSummaryName();
+    }
+
+    @Override
+    public void prepareForMasterUse() {
+        delegate.prepareForMasterUse();
+    }
+
+    @Override
+    public StoreObjectAccessor newAccessor(String path) {
+        return new ListeningAccessor(path, delegate.newAccessor(path));
+    }
+
+    @Override
+    public void createSubPath(String subPath) {
+        if (writesFailSilently)
+            return;
+        
+        for (ObjectStoreTransactionListener listener: listeners)
+            listener.recordQueryOut("creating path "+subPath, 1+subPath.length());
+        delegate.createSubPath(subPath);
+    }
+
+    @Override
+    public List<String> listContentsWithSubPath(String subPath) {
+        for (ObjectStoreTransactionListener listener: listeners)
+            listener.recordQueryOut("requesting list "+subPath, 1+subPath.length());
+        
+        List<String> result = delegate.listContentsWithSubPath(subPath);
+        
+        for (ObjectStoreTransactionListener listener: listeners)
+            listener.recordDataIn("receiving list "+subPath, result.toString().length());
+        return result;
+    }
+
+    @Override
+    public void close() {
+        delegate.close();
+    }
+
+    @Override
+    public void injectManagementContext(ManagementContext managementContext) {
+        delegate.injectManagementContext(managementContext);
+    }
+    
+    @Override
+    public void prepareForSharedUse(PersistMode persistMode, HighAvailabilityMode haMode) {
+        delegate.prepareForSharedUse(persistMode, haMode);
+    }
+
+    @Override
+    public void deleteCompletely() {
+        for (ObjectStoreTransactionListener listener: listeners)
+            listener.recordDataOut("deleting completely", 1);
+        delegate.deleteCompletely();
+    }
+
+    public class ListeningAccessor implements StoreObjectAccessor {
+
+        protected final String path;
+        protected final StoreObjectAccessor delegate;
+        
+        public ListeningAccessor(String path, StoreObjectAccessor delegate) {
+            this.path = path;
+            this.delegate = delegate;
+        }
+        @Override
+        public boolean exists() {
+            return delegate.exists();
+        }
+        @Override
+        public void put(String val) {
+            if (writesFailSilently)
+                return;
+
+            for (ObjectStoreTransactionListener listener: listeners)
+                listener.recordDataOut("writing "+path, val.length());
+            delegate.put(val);
+        }
+        @Override
+        public void append(String s) {
+            if (writesFailSilently)
+                return;
+
+            for (ObjectStoreTransactionListener listener: listeners)
+                listener.recordDataOut("appending "+path, s.length());
+            delegate.append(s);
+        }
+        @Override
+        public void delete() {
+            if (writesFailSilently)
+                return;
+
+            for (ObjectStoreTransactionListener listener: listeners)
+                listener.recordQueryOut("deleting "+path, path.length());
+            delegate.delete();
+        }
+        @Override
+        public String get() {
+            for (ObjectStoreTransactionListener listener: listeners)
+                listener.recordQueryOut("requesting "+path, path.length());
+            String result = delegate.get();
+            
+            for (ObjectStoreTransactionListener listener: listeners)
+                listener.recordDataIn("reading "+path, (result==null ? 0 : result.length()));
+            return result;
+        }
+        @Override
+        public byte[] getBytes() {
+            return get().getBytes();
+        }
+        @Override
+        public Date getLastModifiedDate() {
+            return delegate.getLastModifiedDate();
+        }
+    }
+
+    public void setWritesFailSilently(boolean writesFailSilently) {
+        this.writesFailSilently = writesFailSilently;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/PersistenceStoreObjectAccessorWriterTestFixture.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/PersistenceStoreObjectAccessorWriterTestFixture.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/PersistenceStoreObjectAccessorWriterTestFixture.java
new file mode 100644
index 0000000..b4ac83f
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/PersistenceStoreObjectAccessorWriterTestFixture.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.mgmt.persist;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.concurrent.Executors;
+
+import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore.StoreObjectAccessorWithLock;
+import org.apache.brooklyn.util.text.Identifiers;
+import org.apache.brooklyn.util.time.Duration;
+import org.apache.brooklyn.util.time.Time;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
+
+public abstract class PersistenceStoreObjectAccessorWriterTestFixture {
+
+    private static final Duration TIMEOUT = Duration.TEN_SECONDS;
+    
+    protected ListeningExecutorService executor;
+    protected StoreObjectAccessorWithLock accessor;
+    
+    @BeforeMethod(alwaysRun=true)
+    public void setUp() throws Exception {
+        executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
+        accessor = newPersistenceStoreObjectAccessor();
+    }
+
+    protected abstract StoreObjectAccessorWithLock newPersistenceStoreObjectAccessor() throws IOException;
+    
+    @AfterMethod(alwaysRun=true)
+    public void tearDown() throws Exception {
+        if (accessor != null) {
+            accessor.delete();
+            accessor.waitForCurrentWrites(Duration.TEN_SECONDS);
+        }
+        if (executor != null) executor.shutdownNow();
+    }
+
+    @Test
+    public void testWritesFile() throws Exception {
+        accessor.put("abc");
+        accessor.waitForCurrentWrites(TIMEOUT);
+
+        assertEquals(accessor.get(), "abc");
+    }
+
+    @Test
+    public void testExists() throws Exception {
+        accessor.put("abc");
+        accessor.waitForCurrentWrites(TIMEOUT);
+        assertTrue(accessor.exists());
+        
+        accessor.delete();
+        accessor.waitForCurrentWrites(TIMEOUT);
+        assertFalse(accessor.exists());
+    }
+    
+    @Test
+    public void testAppendsFile() throws Exception {
+        accessor.put("abc\n");
+        accessor.append("def\n");
+        accessor.waitForCurrentWrites(TIMEOUT);
+
+        assertEquals(accessor.get(), "abc\ndef\n");
+    }
+
+    /** most storage systems support <= 1ms resolution; but some file systems -- esp FAT and OSX HFS+ are much much higher! */
+    protected Duration getLastModifiedResolution() {
+        return Duration.millis(1);
+    }
+    
+    @Test
+    public void testLastModifiedTime() throws Exception {
+        accessor.delete();
+        Assert.assertNull(accessor.getLastModifiedDate());
+        accessor.put("abc");
+        accessor.waitForCurrentWrites(TIMEOUT);
+        Date write1 = accessor.getLastModifiedDate();
+        Assert.assertNotNull(write1);
+        
+        Time.sleep(getLastModifiedResolution().times(2));
+        accessor.put("abc");
+        accessor.waitForCurrentWrites(TIMEOUT);
+        Date write2 = accessor.getLastModifiedDate();
+        Assert.assertNotNull(write2);
+        Assert.assertTrue(write2.after(write1), "dates are "+write1+" ("+write1.getTime()+") and "+write2+" ("+write2.getTime()+") ");
+    }
+    
+    @Test
+    public void testWriteBacklogThenDeleteWillLeaveFileDeleted() throws Exception {
+        String big = makeBigString(biggishSize());
+        
+        accessor.put(big);
+        accessor.put(big);
+        accessor.delete();
+        
+        accessor.waitForCurrentWrites(TIMEOUT);
+        assertFalse(accessor.exists());
+    }
+
+    protected int biggishSize() {
+        return 100000;
+    }
+    
+    protected String makeBigString(int size) {
+        // prefer non-random so can't be compressed
+        return Identifiers.makeRandomBase64Id(size);
+//        return com.google.common.base.Strings.repeat("x", size);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializerTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializerTest.java
new file mode 100644
index 0000000..d95cc0a
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializerTest.java
@@ -0,0 +1,455 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.mgmt.persist;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+import org.apache.brooklyn.location.core.SimulatedLocation;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.test.TestResourceUnavailableException;
+import org.apache.brooklyn.util.collections.MutableList;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.collections.MutableSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import org.apache.brooklyn.api.catalog.CatalogItem;
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoPersister.LookupContext;
+import org.apache.brooklyn.api.objs.BrooklynObject;
+import org.apache.brooklyn.api.objs.BrooklynObjectType;
+import org.apache.brooklyn.api.policy.Policy;
+import org.apache.brooklyn.api.sensor.Enricher;
+import org.apache.brooklyn.api.sensor.Feed;
+import org.apache.brooklyn.core.catalog.internal.CatalogItemBuilder;
+import org.apache.brooklyn.core.catalog.internal.CatalogItemDtoAbstract;
+import org.apache.brooklyn.core.catalog.internal.CatalogTestUtils;
+import org.apache.brooklyn.core.mgmt.osgi.OsgiTestResources;
+import org.apache.brooklyn.core.mgmt.osgi.OsgiVersionMoreEntityTest;
+import org.apache.brooklyn.core.mgmt.persist.XmlMementoSerializer;
+import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
+import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.entity.core.Entities;
+import org.apache.brooklyn.entity.group.DynamicCluster;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+
+public class XmlMementoSerializerTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(XmlMementoSerializerTest.class);
+
+    private XmlMementoSerializer<Object> serializer;
+
+    @BeforeMethod(alwaysRun=true)
+    public void setUp() throws Exception {
+        serializer = new XmlMementoSerializer<Object>(XmlMementoSerializerTest.class.getClassLoader());
+    }
+
+    @Test
+    public void testMutableSet() throws Exception {
+        Set<?> obj = MutableSet.of("123");
+        assertSerializeAndDeserialize(obj);
+    }
+
+    @Test
+    public void testLinkedHashSet() throws Exception {
+        Set<String> obj = new LinkedHashSet<String>();
+        obj.add("123");
+        assertSerializeAndDeserialize(obj);
+    }
+
+    @Test
+    public void testImmutableSet() throws Exception {
+        Set<String> obj = ImmutableSet.of("123");
+        assertSerializeAndDeserialize(obj);
+    }
+
+    @Test
+    public void testMutableList() throws Exception {
+        List<?> obj = MutableList.of("123");
+        assertSerializeAndDeserialize(obj);
+    }
+
+    @Test
+    public void testLinkedList() throws Exception {
+        List<String> obj = new LinkedList<String>();
+        obj.add("123");
+        assertSerializeAndDeserialize(obj);
+    }
+
+    @Test
+    public void testArraysAsList() throws Exception {
+        // For some reason Arrays.asList used in the catalog's libraries can't be deserialized correctly,
+        // but here works perfectly - the generated catalog xml contains
+        //    <libraries class="list">
+        //      <a ...>
+        //        <bundle....>
+        // which is deserialized as an ArrayList with a single member array of bundles.
+        // The cause is the class="list" type which should be java.util.Arrays$ArrayList instead.
+        Collection<String> obj = Arrays.asList("a", "b");
+        assertSerializeAndDeserialize(obj);
+    }
+
+    @Test
+    public void testImmutableList() throws Exception {
+        List<String> obj = ImmutableList.of("123");
+        assertSerializeAndDeserialize(obj);
+    }
+
+    @Test
+    public void testMutableMap() throws Exception {
+        Map<?,?> obj = MutableMap.of("mykey", "myval");
+        assertSerializeAndDeserialize(obj);
+    }
+
+    @Test
+    public void testLinkedHashMap() throws Exception {
+        Map<String,String> obj = new LinkedHashMap<String,String>();
+        obj.put("mykey", "myval");
+        assertSerializeAndDeserialize(obj);
+    }
+
+    @Test
+    public void testImmutableMap() throws Exception {
+        Map<?,?> obj = ImmutableMap.of("mykey", "myval");
+        assertSerializeAndDeserialize(obj);
+    }
+
+    @Test
+    public void testClass() throws Exception {
+        Class<?> t = XmlMementoSerializer.class;
+        assertSerializeAndDeserialize(t);
+    }
+
+    @Test
+    public void testEntity() throws Exception {
+        final TestApplication app = TestApplication.Factory.newManagedInstanceForTests();
+        ManagementContext managementContext = app.getManagementContext();
+        try {
+            serializer.setLookupContext(new LookupContextImpl(managementContext,
+                    ImmutableList.of(app), ImmutableList.<Location>of(), ImmutableList.<Policy>of(),
+                    ImmutableList.<Enricher>of(), ImmutableList.<Feed>of(), ImmutableList.<CatalogItem<?, ?>>of(), true));
+            assertSerializeAndDeserialize(app);
+        } finally {
+            Entities.destroyAll(managementContext);
+        }
+    }
+
+    @Test
+    public void testLocation() throws Exception {
+        final TestApplication app = TestApplication.Factory.newManagedInstanceForTests();
+        ManagementContext managementContext = app.getManagementContext();
+        try {
+            @SuppressWarnings("deprecation")
+            final Location loc = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
+            serializer.setLookupContext(new LookupContextImpl(managementContext,
+                    ImmutableList.<Entity>of(), ImmutableList.of(loc), ImmutableList.<Policy>of(),
+                    ImmutableList.<Enricher>of(), ImmutableList.<Feed>of(), ImmutableList.<CatalogItem<?, ?>>of(), true));
+            assertSerializeAndDeserialize(loc);
+        } finally {
+            Entities.destroyAll(managementContext);
+        }
+    }
+
+    @Test
+    public void testCatalogItem() throws Exception {
+        final TestApplication app = TestApplication.Factory.newManagedInstanceForTests();
+        ManagementContext managementContext = app.getManagementContext();
+        try {
+            CatalogItem<?, ?> catalogItem = CatalogItemBuilder.newEntity("symbolicName", "0.0.1")
+                    .displayName("test catalog item")
+                    .description("description")
+                    .plan("yaml plan")
+                    .iconUrl("iconUrl")
+                    .libraries(CatalogItemDtoAbstract.parseLibraries(ImmutableList.of("library-url")))
+                    .build();
+            serializer.setLookupContext(new LookupContextImpl(managementContext,
+                    ImmutableList.<Entity>of(), ImmutableList.<Location>of(), ImmutableList.<Policy>of(),
+                    ImmutableList.<Enricher>of(), ImmutableList.<Feed>of(), ImmutableList.of(catalogItem), true));
+            assertSerializeAndDeserialize(catalogItem);
+        } finally {
+            Entities.destroyAll(managementContext);
+        }
+    }
+
+    @Test
+    public void testEntitySpec() throws Exception {
+        EntitySpec<?> obj = EntitySpec.create(TestEntity.class);
+        assertSerializeAndDeserialize(obj);
+    }
+    
+    @Test
+    public void testEntitySpecFromOsgi() throws Exception {
+        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_V1_PATH);
+        ManagementContext mgmt = LocalManagementContextForTests.builder(true).disableOsgi(false).build();
+        try {
+            CatalogItem<?, ?> ci = OsgiVersionMoreEntityTest.addMoreEntityV1(mgmt, "1.0");
+            
+            EntitySpec<DynamicCluster> spec = EntitySpec.create(DynamicCluster.class)
+                .configure(DynamicCluster.INITIAL_SIZE, 1)
+                .configure(DynamicCluster.MEMBER_SPEC, CatalogTestUtils.createEssentialEntitySpec(mgmt, ci));
+    
+            serializer.setLookupContext(new LookupContextImpl(mgmt,
+                ImmutableList.<Entity>of(), ImmutableList.<Location>of(), ImmutableList.<Policy>of(),
+                ImmutableList.<Enricher>of(), ImmutableList.<Feed>of(), ImmutableList.<CatalogItem<?,?>>of(), true));
+            assertSerializeAndDeserialize(spec);
+        } finally {
+            Entities.destroyAllCatching(mgmt);
+        }
+    }
+
+    @Test
+    public void testImmutableCollectionsWithDanglingEntityRef() throws Exception {
+        // If there's a dangling entity in an ImmutableList etc, then discard it entirely.
+        // If we try to insert null then it fails, breaking the deserialization of that entire file.
+        
+        final TestApplication app = TestApplication.Factory.newManagedInstanceForTests();
+        final TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
+        ManagementContext managementContext = app.getManagementContext();
+        try {
+            serializer.setLookupContext(new LookupContextImpl(managementContext,
+                    ImmutableList.of(app), ImmutableList.<Location>of(), ImmutableList.<Policy>of(),
+                    ImmutableList.<Enricher>of(), ImmutableList.<Feed>of(), ImmutableList.<CatalogItem<?, ?>>of(), false));
+            
+            List<?> resultList = serializeAndDeserialize(ImmutableList.of(app, entity));
+            assertEquals(resultList, ImmutableList.of(app));
+            
+            Set<?> resultSet = serializeAndDeserialize(ImmutableSet.of(app, entity));
+            assertEquals(resultSet, ImmutableSet.of(app));
+            
+            Map<?, ?> resultMap = serializeAndDeserialize(ImmutableMap.of(app, "appval", "appkey", app, entity, "entityval", "entityKey", entity));
+            assertEquals(resultMap, ImmutableMap.of(app, "appval", "appkey", app));
+
+        } finally {
+            Entities.destroyAll(managementContext);
+        }
+    }
+
+    @Test
+    public void testFieldReffingEntity() throws Exception {
+        final TestApplication app = TestApplication.Factory.newManagedInstanceForTests();
+        ReffingEntity reffer = new ReffingEntity(app);
+        ManagementContext managementContext = app.getManagementContext();
+        try {
+            serializer.setLookupContext(new LookupContextImpl(managementContext,
+                    ImmutableList.of(app), ImmutableList.<Location>of(), ImmutableList.<Policy>of(),
+                    ImmutableList.<Enricher>of(), ImmutableList.<Feed>of(), ImmutableList.<CatalogItem<?, ?>>of(), true));
+            ReffingEntity reffer2 = assertSerializeAndDeserialize(reffer);
+            assertEquals(reffer2.entity, app);
+        } finally {
+            Entities.destroyAll(managementContext);
+        }
+    }
+
+    @Test
+    public void testUntypedFieldReffingEntity() throws Exception {
+        final TestApplication app = TestApplication.Factory.newManagedInstanceForTests();
+        ReffingEntity reffer = new ReffingEntity((Object)app);
+        ManagementContext managementContext = app.getManagementContext();
+        try {
+            serializer.setLookupContext(new LookupContextImpl(managementContext,
+                    ImmutableList.of(app), ImmutableList.<Location>of(), ImmutableList.<Policy>of(),
+                    ImmutableList.<Enricher>of(), ImmutableList.<Feed>of(), ImmutableList.<CatalogItem<?, ?>>of(), true));
+            ReffingEntity reffer2 = assertSerializeAndDeserialize(reffer);
+            assertEquals(reffer2.obj, app);
+        } finally {
+            Entities.destroyAll(managementContext);
+        }
+    }
+
+    public static class ReffingEntity {
+        public Entity entity;
+        public Object obj;
+        public ReffingEntity(Entity entity) {
+            this.entity = entity;
+        }
+        public ReffingEntity(Object obj) {
+            this.obj = obj;
+        }
+        @Override
+        public boolean equals(Object o) {
+            return (o instanceof ReffingEntity) && Objects.equal(entity, ((ReffingEntity)o).entity) && Objects.equal(obj, ((ReffingEntity)o).obj);
+        }
+        @Override
+        public int hashCode() {
+            return Objects.hashCode(entity, obj);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private <T> T assertSerializeAndDeserialize(T obj) throws Exception {
+        String serializedForm = serializer.toString(obj);
+        LOG.info("serializedForm=" + serializedForm);
+        Object deserialized = serializer.fromString(serializedForm);
+        assertEquals(deserialized, obj, "serializedForm="+serializedForm);
+        return (T) deserialized;
+    }
+
+    @SuppressWarnings("unchecked")
+    private <T> T serializeAndDeserialize(T obj) throws Exception {
+        String serializedForm = serializer.toString(obj);
+        LOG.info("serializedForm=" + serializedForm);
+        return (T) serializer.fromString(serializedForm);
+    }
+
+    static class LookupContextImpl implements LookupContext {
+        private final ManagementContext mgmt;
+        private final Map<String, Entity> entities;
+        private final Map<String, Location> locations;
+        private final Map<String, Policy> policies;
+        private final Map<String, Enricher> enrichers;
+        private final Map<String, Feed> feeds;
+        private final Map<String, CatalogItem<?, ?>> catalogItems;
+        private final boolean failOnDangling;
+
+        LookupContextImpl(ManagementContext mgmt, Iterable<? extends Entity> entities, Iterable<? extends Location> locations,
+                Iterable<? extends Policy> policies, Iterable<? extends Enricher> enrichers, Iterable<? extends Feed> feeds,
+                Iterable<? extends CatalogItem<?, ?>> catalogItems, boolean failOnDangling) {
+            this.mgmt = mgmt;
+            this.entities = Maps.newLinkedHashMap();
+            this.locations = Maps.newLinkedHashMap();
+            this.policies = Maps.newLinkedHashMap();
+            this.enrichers = Maps.newLinkedHashMap();
+            this.feeds = Maps.newLinkedHashMap();
+            this.catalogItems = Maps.newLinkedHashMap();
+            for (Entity entity : entities) this.entities.put(entity.getId(), entity);
+            for (Location location : locations) this.locations.put(location.getId(), location);
+            for (Policy policy : policies) this.policies.put(policy.getId(), policy);
+            for (Enricher enricher : enrichers) this.enrichers.put(enricher.getId(), enricher);
+            for (Feed feed : feeds) this.feeds.put(feed.getId(), feed);
+            for (CatalogItem<?, ?> catalogItem : catalogItems) this.catalogItems.put(catalogItem.getId(), catalogItem);
+            this.failOnDangling = failOnDangling;
+        }
+        LookupContextImpl(ManagementContext mgmt, Map<String,? extends Entity> entities, Map<String,? extends Location> locations,
+                Map<String,? extends Policy> policies, Map<String,? extends Enricher> enrichers, Map<String,? extends Feed> feeds,
+                Map<String, ? extends CatalogItem<?, ?>> catalogItems, boolean failOnDangling) {
+            this.mgmt = mgmt;
+            this.entities = ImmutableMap.copyOf(entities);
+            this.locations = ImmutableMap.copyOf(locations);
+            this.policies = ImmutableMap.copyOf(policies);
+            this.enrichers = ImmutableMap.copyOf(enrichers);
+            this.feeds = ImmutableMap.copyOf(feeds);
+            this.catalogItems = ImmutableMap.copyOf(catalogItems);
+            this.failOnDangling = failOnDangling;
+        }
+        @Override public ManagementContext lookupManagementContext() {
+            return mgmt;
+        }
+        @Override public Entity lookupEntity(String id) {
+            if (entities.containsKey(id)) {
+                return entities.get(id);
+            }
+            if (failOnDangling) {
+                throw new NoSuchElementException("no entity with id "+id+"; contenders are "+entities.keySet());
+            }
+            return null;
+        }
+        @Override public Location lookupLocation(String id) {
+            if (locations.containsKey(id)) {
+                return locations.get(id);
+            }
+            if (failOnDangling) {
+                throw new NoSuchElementException("no location with id "+id+"; contenders are "+locations.keySet());
+            }
+            return null;
+        }
+        @Override public Policy lookupPolicy(String id) {
+            if (policies.containsKey(id)) {
+                return policies.get(id);
+            }
+            if (failOnDangling) {
+                throw new NoSuchElementException("no policy with id "+id+"; contenders are "+policies.keySet());
+            }
+            return null;
+        }
+        @Override public Enricher lookupEnricher(String id) {
+            if (enrichers.containsKey(id)) {
+                return enrichers.get(id);
+            }
+            if (failOnDangling) {
+                throw new NoSuchElementException("no enricher with id "+id+"; contenders are "+enrichers.keySet());
+            }
+            return null;
+        }
+        @Override public Feed lookupFeed(String id) {
+            if (feeds.containsKey(id)) {
+                return feeds.get(id);
+            }
+            if (failOnDangling) {
+                throw new NoSuchElementException("no feed with id "+id+"; contenders are "+feeds.keySet());
+            }
+            return null;
+        }
+        @Override public CatalogItem<?, ?> lookupCatalogItem(String id) {
+            if (catalogItems.containsKey(id)) {
+                return catalogItems.get(id);
+            }
+            if (failOnDangling) {
+                throw new NoSuchElementException("no catalog item with id "+id+"; contenders are "+catalogItems.keySet());
+            }
+            return null;
+        }
+        
+        @Override
+        public BrooklynObject lookup(BrooklynObjectType type, String id) {
+            switch (type) {
+            case CATALOG_ITEM: return lookupCatalogItem(id);
+            case ENRICHER: return lookupEnricher(id);
+            case ENTITY: return lookupEntity(id);
+            case FEED: return lookupFeed(id);
+            case LOCATION: return lookupLocation(id);
+            case POLICY: return lookupPolicy(id);
+            case UNKNOWN: return null;
+            }
+            throw new IllegalStateException("Unexpected type "+type+" / id "+id);
+        }
+        @Override
+        public BrooklynObject peek(BrooklynObjectType type, String id) {
+            switch (type) {
+            case CATALOG_ITEM: return catalogItems.get(id);
+            case ENRICHER: return enrichers.get(id);
+            case ENTITY: return entities.get(id);
+            case FEED: return feeds.get(id);
+            case LOCATION: return locations.get(id);
+            case POLICY: return policies.get(id);
+            case UNKNOWN: return null;
+            }
+            throw new IllegalStateException("Unexpected type "+type+" / id "+id);
+        }
+    };
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
index e4f6df9..37f569e 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
@@ -46,7 +46,7 @@ import org.apache.brooklyn.core.test.camp.brooklyn.lite.CampPlatformWithJustBroo
 import org.apache.brooklyn.core.test.camp.brooklyn.lite.TestAppAssemblyInstantiator;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.policy.core.AbstractPolicy;
-import org.apache.brooklyn.location.basic.LocalhostMachineProvisioningLocation;
+import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
 
 import com.google.common.base.Joiner;
 import com.google.common.base.Throwables;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEnricherTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEnricherTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEnricherTest.java
index e499dd9..c44c9ca 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEnricherTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEnricherTest.java
@@ -54,7 +54,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
-import org.apache.brooklyn.location.basic.SimulatedLocation;
+import org.apache.brooklyn.location.core.SimulatedLocation;
 
 import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableList;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
index 7571bea..3a3d5f2 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
@@ -78,7 +78,7 @@ import org.apache.brooklyn.util.exceptions.RuntimeInterruptedException;
 import org.apache.brooklyn.util.time.Durations;
 import org.testng.Assert;
 import org.testng.annotations.Test;
-import org.apache.brooklyn.location.basic.LocationConfigTest.MyLocation;
+import org.apache.brooklyn.location.core.LocationConfigTest.MyLocation;
 
 import com.google.common.base.Objects;
 import com.google.common.base.Predicates;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindFeedTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindFeedTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindFeedTest.java
index 3620070..f27bf65 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindFeedTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindFeedTest.java
@@ -58,8 +58,8 @@ import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
-import org.apache.brooklyn.location.basic.LocalhostMachineProvisioningLocation;
-import org.apache.brooklyn.location.basic.SshMachineLocation;
+import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
+import org.apache.brooklyn.location.ssh.SshMachineLocation;
 
 import com.google.common.base.Function;
 import com.google.common.base.Predicates;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindLocalhostLocationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindLocalhostLocationTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindLocalhostLocationTest.java
index 647d9f8..91b6064 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindLocalhostLocationTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindLocalhostLocationTest.java
@@ -30,8 +30,8 @@ import org.testng.annotations.Test;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoManifest;
 import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.location.basic.LocalhostMachineProvisioningLocation;
-import org.apache.brooklyn.location.basic.SshMachineLocation;
+import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
+import org.apache.brooklyn.location.ssh.SshMachineLocation;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindLocationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindLocationTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindLocationTest.java
index b5608dd..fe60599 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindLocationTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindLocationTest.java
@@ -44,7 +44,7 @@ import org.apache.brooklyn.util.core.flags.SetFromFlag;
 import org.testng.Assert;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
-import org.apache.brooklyn.location.basic.AbstractLocation;
+import org.apache.brooklyn.location.core.AbstractLocation;
 
 import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableList;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
index 5cc5893..71ce08a 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
@@ -22,7 +22,7 @@ import java.io.File;
 
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.rebind.RebindExceptionHandler;
-import org.apache.brooklyn.core.mgmt.rebind.persister.PersistenceObjectStore;
+import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore;
 
 /**
  * See {@link RebindTestFixture#rebind(RebindOptions)} and {@link RebindTestUtils#rebind(RebindOptions)}.

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindPolicyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindPolicyTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindPolicyTest.java
index 2ec19ef..44ab0eb 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindPolicyTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindPolicyTest.java
@@ -47,7 +47,7 @@ import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.collections.MutableSet;
 import org.apache.brooklyn.util.core.flags.SetFromFlag;
 import org.testng.annotations.Test;
-import org.apache.brooklyn.location.basic.Locations;
+import org.apache.brooklyn.location.core.Locations;
 
 import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableSet;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindSshMachineLocationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindSshMachineLocationTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindSshMachineLocationTest.java
index 21de755..92fdb55 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindSshMachineLocationTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindSshMachineLocationTest.java
@@ -28,8 +28,8 @@ import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.location.basic.FixedListMachineProvisioningLocation;
-import org.apache.brooklyn.location.basic.SshMachineLocation;
+import org.apache.brooklyn.location.byon.FixedListMachineProvisioningLocation;
+import org.apache.brooklyn.location.ssh.SshMachineLocation;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
index 2d9e60e..d75e563 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
@@ -43,9 +43,9 @@ import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoManifest;
 import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
-import org.apache.brooklyn.core.mgmt.rebind.persister.BrooklynMementoPersisterToObjectStore;
-import org.apache.brooklyn.core.mgmt.rebind.persister.FileBasedObjectStore;
-import org.apache.brooklyn.core.mgmt.rebind.persister.PersistMode;
+import org.apache.brooklyn.core.mgmt.persist.BrooklynMementoPersisterToObjectStore;
+import org.apache.brooklyn.core.mgmt.persist.FileBasedObjectStore;
+import org.apache.brooklyn.core.mgmt.persist.PersistMode;
 import org.apache.brooklyn.entity.core.Entities;
 import org.apache.brooklyn.entity.core.EntityFunctions;
 import org.apache.brooklyn.entity.core.StartableApplication;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
index 6d1ac24..e5696c2f 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
@@ -42,15 +42,15 @@ import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.mgmt.ha.ManagementPlaneSyncRecordPersisterToObjectStore;
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
+import org.apache.brooklyn.core.mgmt.persist.BrooklynMementoPersisterToObjectStore;
+import org.apache.brooklyn.core.mgmt.persist.FileBasedObjectStore;
+import org.apache.brooklyn.core.mgmt.persist.PersistMode;
+import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore;
 import org.apache.brooklyn.core.mgmt.rebind.PersistenceExceptionHandlerImpl;
 import org.apache.brooklyn.core.mgmt.rebind.RebindExceptionHandlerImpl;
 import org.apache.brooklyn.core.mgmt.rebind.RebindManagerImpl;
 import org.apache.brooklyn.core.mgmt.rebind.Dumpers.Pointer;
 import org.apache.brooklyn.core.mgmt.rebind.dto.MementosGenerators;
-import org.apache.brooklyn.core.mgmt.rebind.persister.BrooklynMementoPersisterToObjectStore;
-import org.apache.brooklyn.core.mgmt.rebind.persister.FileBasedObjectStore;
-import org.apache.brooklyn.core.mgmt.rebind.persister.PersistMode;
-import org.apache.brooklyn.core.mgmt.rebind.persister.PersistenceObjectStore;
 import org.apache.brooklyn.core.server.BrooklynServerConfig;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
 import org.apache.brooklyn.util.io.FileUtil;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterFileBasedTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterFileBasedTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterFileBasedTest.java
deleted file mode 100644
index 608d4aa..0000000
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterFileBasedTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.core.mgmt.rebind.persister;
-
-import java.io.File;
-
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
-import org.apache.brooklyn.core.mgmt.rebind.persister.FileBasedObjectStore;
-import org.apache.brooklyn.util.javalang.JavaClassNames;
-import org.apache.brooklyn.util.os.Os;
-import org.apache.brooklyn.util.time.Duration;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.Test;
-
-/**
- * @author Andrea Turli
- */
-@Test
-public class BrooklynMementoPersisterFileBasedTest extends BrooklynMementoPersisterTestFixture {
-
-    protected File mementoDir;
-    
-    @Override
-    protected ManagementContext newPersistingManagementContext() {
-        mementoDir = Os.newTempDir(JavaClassNames.cleanSimpleClassName(this));
-        Os.deleteOnExitRecursively(mementoDir);
-        return RebindTestUtils.managementContextBuilder(classLoader, new FileBasedObjectStore(mementoDir))
-            .persistPeriod(Duration.millis(10)).buildStarted();
-    }
-
-    @Override
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        super.tearDown();
-        mementoDir = Os.deleteRecursively(mementoDir).asNullOrThrowing();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterInMemorySizeIntegrationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterInMemorySizeIntegrationTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterInMemorySizeIntegrationTest.java
deleted file mode 100644
index 3aa176d..0000000
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterInMemorySizeIntegrationTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.core.mgmt.rebind.persister;
-
-import java.io.IOException;
-import java.util.concurrent.TimeoutException;
-
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
-import org.apache.brooklyn.core.mgmt.rebind.persister.ListeningObjectStore.RecordingTransactionListener;
-import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.apache.brooklyn.entity.core.EntityInternal;
-import org.apache.brooklyn.util.text.Identifiers;
-import org.apache.brooklyn.util.time.Duration;
-import org.apache.brooklyn.util.time.Time;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-/** uses recorder to ensure not too much data is written */
-@Test
-public class BrooklynMementoPersisterInMemorySizeIntegrationTest extends BrooklynMementoPersisterTestFixture {
-
-    protected RecordingTransactionListener recorder;
-    
-    protected ManagementContext newPersistingManagementContext() {
-        recorder = new RecordingTransactionListener("in-mem-test-"+Identifiers.makeRandomId(4));
-        return RebindTestUtils.managementContextBuilder(classLoader, 
-            new ListeningObjectStore(new InMemoryObjectStore(), recorder))
-            .persistPeriod(Duration.millis(100)).buildStarted();
-    }
-    
-    public void testPersistenceVolumeFast() throws IOException, TimeoutException, InterruptedException {
-        doTestPersistenceVolume(50*1000, false, true);
-    }
-    @Test(groups="Integration",invocationCount=20)
-    public void testPersistenceVolumeFastManyTimes() throws IOException, TimeoutException, InterruptedException {
-        doTestPersistenceVolume(50*1000, false, true);
-    }
-    @Test(groups="Integration")
-    public void testPersistenceVolumeWaiting() throws IOException, TimeoutException, InterruptedException {
-        // by waiting we ensure there aren't extra writes going on
-        doTestPersistenceVolume(50*1000, true, true);
-    }
-    public void testPersistenceVolumeFastNoTrigger() throws IOException, TimeoutException, InterruptedException {
-        doTestPersistenceVolume(50*1000, false, false);
-    }
-    @Test(groups="Integration",invocationCount=20)
-    public void testPersistenceVolumeFastNoTriggerManyTimes() throws IOException, TimeoutException, InterruptedException {
-        doTestPersistenceVolume(50*1000, false, false);
-    }
-    
-    protected void doTestPersistenceVolume(int bigBlockSize, boolean forceDelay, boolean canTrigger) throws IOException, TimeoutException, InterruptedException {
-        if (forceDelay) Time.sleep(Duration.FIVE_SECONDS);
-        else recorder.blockUntilDataWrittenExceeds(512, Duration.FIVE_SECONDS);
-        localManagementContext.getRebindManager().waitForPendingComplete(Duration.FIVE_SECONDS, canTrigger);
-        
-        long out1 = recorder.getBytesOut();
-        int filesOut1 = recorder.getCountDataOut();
-        Assert.assertTrue(out1>512, "should have written at least 0.5k, only wrote "+out1);
-        Assert.assertTrue(out1<30*1000, "should have written less than 30k, wrote "+out1);
-        Assert.assertTrue(filesOut1<30, "should have written fewer than 30 files, wrote "+out1);
-        
-        ((EntityInternal)app).setAttribute(TestEntity.NAME, "hello world");
-        if (forceDelay) Time.sleep(Duration.FIVE_SECONDS);
-        else recorder.blockUntilDataWrittenExceeds(out1+10, Duration.FIVE_SECONDS);
-        localManagementContext.getRebindManager().waitForPendingComplete(Duration.FIVE_SECONDS, canTrigger);
-        
-        long out2 = recorder.getBytesOut();
-        Assert.assertTrue(out2-out1>10, "should have written more data");
-        int filesOut2 = recorder.getCountDataOut();
-        Assert.assertTrue(filesOut2>filesOut1, "should have written more files");
-        
-        Assert.assertTrue(out2<50*1000, "should have written less than 50k, wrote "+out1);
-        Assert.assertTrue(filesOut2<40, "should have written fewer than 40 files, wrote "+out1);
-        
-        ((EntityInternal)entity).setAttribute(TestEntity.NAME, Identifiers.makeRandomId(bigBlockSize));
-        if (forceDelay) Time.sleep(Duration.FIVE_SECONDS);
-        else recorder.blockUntilDataWrittenExceeds(out2+bigBlockSize, Duration.FIVE_SECONDS);
-        localManagementContext.getRebindManager().waitForPendingComplete(Duration.FIVE_SECONDS, canTrigger);
-
-        long out3 = recorder.getBytesOut();
-        Assert.assertTrue(out3-out2 > bigBlockSize, "should have written 50k more data, only wrote "+out3+" compared with "+out2);
-        int filesOut3 = recorder.getCountDataOut();
-        Assert.assertTrue(filesOut3>filesOut2, "should have written more files");
-        
-        Assert.assertTrue(out2<100*1000+bigBlockSize, "should have written less than 100k+block, wrote "+out1);
-        Assert.assertTrue(filesOut2<60, "should have written fewer than 60 files, wrote "+out1);
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterInMemoryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterInMemoryTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterInMemoryTest.java
deleted file mode 100644
index 837c3c3..0000000
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterInMemoryTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.core.mgmt.rebind.persister;
-
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
-import org.apache.brooklyn.util.time.Duration;
-import org.testng.annotations.Test;
-
-@Test
-public class BrooklynMementoPersisterInMemoryTest extends BrooklynMementoPersisterTestFixture {
-
-    protected ManagementContext newPersistingManagementContext() {
-        return RebindTestUtils.managementContextBuilder(classLoader, new InMemoryObjectStore())
-            .persistPeriod(Duration.millis(10)).buildStarted();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterTestFixture.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterTestFixture.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterTestFixture.java
deleted file mode 100644
index fb231d8..0000000
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/BrooklynMementoPersisterTestFixture.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.core.mgmt.rebind.persister;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.location.LocationSpec;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.api.mgmt.rebind.PersistenceExceptionHandler;
-import org.apache.brooklyn.api.mgmt.rebind.RebindManager.RebindFailureMode;
-import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMemento;
-import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoPersister;
-import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoRawData;
-import org.apache.brooklyn.api.policy.Policy;
-import org.apache.brooklyn.api.sensor.Enricher;
-import org.apache.brooklyn.core.mgmt.rebind.PersistenceExceptionHandlerImpl;
-import org.apache.brooklyn.core.mgmt.rebind.RebindContextImpl;
-import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
-import org.apache.brooklyn.core.mgmt.rebind.RecordingRebindExceptionHandler;
-import org.apache.brooklyn.core.mgmt.rebind.persister.BrooklynMementoPersisterToObjectStore;
-import org.apache.brooklyn.core.mgmt.rebind.persister.PersistenceObjectStore;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.apache.brooklyn.core.test.policy.TestPolicy;
-import org.apache.brooklyn.entity.core.Entities;
-import org.apache.brooklyn.entity.factory.ApplicationBuilder;
-import org.apache.brooklyn.sensor.enricher.Enrichers;
-import org.testng.SkipException;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-import org.apache.brooklyn.location.basic.SshMachineLocation;
-
-import com.google.common.collect.Iterables;
-
-/**
- * @author Andrea Turli
- */
-public abstract class BrooklynMementoPersisterTestFixture {
-
-    protected ClassLoader classLoader = getClass().getClassLoader();
-    protected BrooklynMementoPersister persister;
-    protected TestApplication app;
-    protected Entity entity;
-    protected Location location;
-    protected ManagementContext localManagementContext;
-    protected Enricher enricher;
-    protected Policy policy;
-    
-    protected PersistenceObjectStore objectStore;
-
-    @BeforeMethod(alwaysRun=true)
-    public void setUp() throws Exception {
-        localManagementContext = newPersistingManagementContext();
-        if (persister==null) {
-            persister = localManagementContext.getRebindManager().getPersister();
-        }
-        if (objectStore==null && persister instanceof BrooklynMementoPersisterToObjectStore) {
-            objectStore = ((BrooklynMementoPersisterToObjectStore)persister).getObjectStore();
-        }
-        app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class), localManagementContext);
-        location =  localManagementContext.getLocationManager()
-            .createLocation(LocationSpec.create(SshMachineLocation.class)
-                .configure("address", "localhost"));
-        entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).location(location));
-        enricher = app.addEnricher(Enrichers.builder().propagatingAll().from(entity).build());
-        app.addPolicy(policy = new TestPolicy());
-    }
-
-    protected abstract ManagementContext newPersistingManagementContext();
-
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (localManagementContext != null) Entities.destroyAll(localManagementContext);
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-        if (persister != null) persister.stop(false);
-        if (objectStore!=null) objectStore.deleteCompletely();
-        persister = null;
-    }
-
-    protected BrooklynMemento loadMemento() throws Exception {
-        RebindTestUtils.waitForPersisted(localManagementContext);
-        
-        RecordingRebindExceptionHandler failFast = new RecordingRebindExceptionHandler(RebindFailureMode.FAIL_FAST, RebindFailureMode.FAIL_FAST);
-        RebindContextImpl rebindContext = new RebindContextImpl(localManagementContext, failFast, classLoader);
-        // here we force these two to be reegistered in order to resolve the enricher and policy
-        // (normally rebind will do that after loading the manifests, but in this test we are just looking at persistence/manifest)
-        rebindContext.registerEntity(app.getId(), app);
-        rebindContext.registerEntity(entity.getId(), entity);
-        
-        BrooklynMemento reloadedMemento = persister.loadMemento(null, rebindContext.lookup(), failFast);
-        return reloadedMemento;
-    }
-    
-    protected BrooklynMementoRawData loadRawMemento(BrooklynMementoPersisterToObjectStore persister) throws Exception {
-        RebindTestUtils.waitForPersisted(localManagementContext);
-        
-        RecordingRebindExceptionHandler failFast = new RecordingRebindExceptionHandler(RebindFailureMode.FAIL_FAST, RebindFailureMode.FAIL_FAST);
-        BrooklynMementoRawData rawMemento = persister.loadMementoRawData(failFast);
-        return rawMemento;
-    }
-    
-    @Test
-    public void testCheckPointAndLoadMemento() throws Exception {
-        BrooklynMemento reloadedMemento = loadMemento();
-        
-        assertNotNull(reloadedMemento);
-        assertTrue(Iterables.contains(reloadedMemento.getEntityIds(), entity.getId()));
-        assertEquals(Iterables.getOnlyElement(reloadedMemento.getLocationIds()), location.getId());
-        assertEquals(Iterables.getOnlyElement(reloadedMemento.getPolicyIds()), policy.getId());
-        assertTrue(reloadedMemento.getEnricherIds().contains(enricher.getId()));
-    }
-
-    @Test
-    public void testDeleteAndLoadMemento() throws Exception {
-        Entities.destroy(entity);
-
-        BrooklynMemento reloadedMemento = loadMemento();
-        
-        assertNotNull(reloadedMemento);
-        assertFalse(Iterables.contains(reloadedMemento.getEntityIds(), entity.getId()));
-        assertEquals(Iterables.getOnlyElement(reloadedMemento.getLocationIds()), location.getId());
-    }
-    
-    @Test
-    public void testLoadAndCheckpointRawMemento() throws Exception {
-        if (persister instanceof BrooklynMementoPersisterToObjectStore) {
-            // Test loading
-            BrooklynMementoRawData rawMemento = loadRawMemento((BrooklynMementoPersisterToObjectStore)persister);
-            assertNotNull(rawMemento);
-            assertTrue(Iterables.contains(rawMemento.getEntities().keySet(), entity.getId()));
-            assertEquals(Iterables.getOnlyElement(rawMemento.getLocations().keySet()), location.getId());
-            assertEquals(Iterables.getOnlyElement(rawMemento.getPolicies().keySet()), policy.getId());
-            assertTrue(rawMemento.getEnrichers().keySet().contains(enricher.getId()));
-            
-            // And test persisting
-            PersistenceExceptionHandler exceptionHandler = PersistenceExceptionHandlerImpl.builder().build();
-            ((BrooklynMementoPersisterToObjectStore) persister).checkpoint(rawMemento, exceptionHandler);
-        } else {
-            throw new SkipException("Persister "+persister+" not a "+BrooklynMementoPersisterToObjectStore.class.getSimpleName());
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/FileBasedObjectStoreTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/FileBasedObjectStoreTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/FileBasedObjectStoreTest.java
deleted file mode 100644
index 56cc10a..0000000
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/FileBasedObjectStoreTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.core.mgmt.rebind.persister;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-
-import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
-import org.apache.brooklyn.core.mgmt.rebind.persister.FileBasedObjectStore;
-import org.apache.brooklyn.core.mgmt.rebind.persister.PersistMode;
-import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
-import org.apache.brooklyn.entity.core.Entities;
-import org.apache.brooklyn.util.io.FileUtil;
-import org.apache.brooklyn.util.os.Os;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import com.google.common.io.Files;
-
-public class FileBasedObjectStoreTest {
-
-    private LocalManagementContextForTests mgmt;
-    private File parentdir;
-    private File basedir;
-    private FileBasedObjectStore store;
-    
-    @BeforeMethod(alwaysRun=true)
-    public void setUp() throws Exception {
-        mgmt = new LocalManagementContextForTests();
-        parentdir = Files.createTempDir();
-        basedir = new File(parentdir, "mystore");
-        store = new FileBasedObjectStore(basedir);
-        store.injectManagementContext(mgmt);
-        store.prepareForSharedUse(PersistMode.AUTO, HighAvailabilityMode.DISABLED);
-    }
-    
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (store != null) store.close();
-        if (parentdir != null) Os.deleteRecursively(basedir);
-        if (mgmt != null) Entities.destroyAll(mgmt);
-    }
-    
-    @Test(groups="Integration")
-    public void testSubPathCreatedWithPermission700() throws Exception {
-        store.createSubPath("mysubdir");
-        File subdir = new File(basedir, "mysubdir");
-        
-        assertFilePermission700(basedir);
-        assertFilePermission700(subdir);
-    }
-    
-    @Test
-    public void testIsMementoDirExistsButEmpty() throws Exception {
-        basedir = new File(parentdir, "testIsMementoDirExistsButEmpty");
-        assertFalse(FileBasedObjectStore.isMementoDirExistButEmpty(basedir));
-        assertFalse(FileBasedObjectStore.isMementoDirExistButEmpty(basedir.getAbsolutePath()));
-        
-        basedir.mkdir();
-        assertTrue(FileBasedObjectStore.isMementoDirExistButEmpty(basedir));
-        assertTrue(FileBasedObjectStore.isMementoDirExistButEmpty(basedir.getAbsolutePath()));
-        
-        new File(basedir, "entities").mkdir();
-        new File(basedir, "locations").mkdir();
-        assertTrue(FileBasedObjectStore.isMementoDirExistButEmpty(basedir));
-        assertTrue(FileBasedObjectStore.isMementoDirExistButEmpty(basedir.getAbsolutePath()));
-        
-        new File(new File(basedir, "locations"), "afile").createNewFile();
-        assertFalse(FileBasedObjectStore.isMementoDirExistButEmpty(basedir));
-        assertFalse(FileBasedObjectStore.isMementoDirExistButEmpty(basedir.getAbsolutePath()));
-    }
-    
-    static void assertFilePermission700(File file) throws FileNotFoundException {
-        assertEquals(FileUtil.getFilePermissions(file).get().substring(1), "rwx------");
-    }
-    
-    static void assertFilePermission600(File file) throws Exception {
-        assertEquals(FileUtil.getFilePermissions(file).get().substring(1), "rw-------");
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/FileBasedStoreObjectAccessorWriterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/FileBasedStoreObjectAccessorWriterTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/FileBasedStoreObjectAccessorWriterTest.java
deleted file mode 100644
index 2363f22..0000000
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/persister/FileBasedStoreObjectAccessorWriterTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.core.mgmt.rebind.persister;
-
-import static org.testng.Assert.assertEquals;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.brooklyn.core.mgmt.rebind.persister.FileBasedStoreObjectAccessor;
-import org.apache.brooklyn.core.mgmt.rebind.persister.StoreObjectAccessorLocking;
-import org.apache.brooklyn.core.mgmt.rebind.persister.PersistenceObjectStore.StoreObjectAccessorWithLock;
-import org.apache.brooklyn.util.os.Os;
-import org.apache.brooklyn.util.time.Duration;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Charsets;
-import com.google.common.collect.ImmutableList;
-import com.google.common.io.Files;
-
-@Test
-public class FileBasedStoreObjectAccessorWriterTest extends PersistenceStoreObjectAccessorWriterTestFixture {
-
-    private File file;
-    
-    protected StoreObjectAccessorWithLock newPersistenceStoreObjectAccessor() throws IOException {
-        file = Os.newTempFile(getClass(), "txt");
-        return new StoreObjectAccessorLocking(new FileBasedStoreObjectAccessor(file, ".tmp"));
-    }
-    
-    @Override
-    protected Duration getLastModifiedResolution() {
-        // OSX is 1s, Windows FAT is 2s !
-        return Duration.seconds(2);
-    }
-    
-    @Test(groups="Integration")
-    public void testLastModifiedTime() throws Exception {
-        super.testLastModifiedTime();
-    }
-    
-    @Test(groups="Integration")
-    public void testFilePermissions600() throws Exception {
-        accessor.put("abc");
-        assertEquals(Files.readLines(file, Charsets.UTF_8), ImmutableList.of("abc"));
-        
-        FileBasedObjectStoreTest.assertFilePermission600(file);
-    }
-}


Mime
View raw message