use of io.fabric8.zookeeper.spring.ZKServerFactoryBean in project fabric8 by jboss-fuse.
the class ProjectDeployerTest method setUp.
@Before
public void setUp() throws Exception {
URL.setURLStreamHandlerFactory(new CustomBundleURLStreamHandlerFactory());
basedir = System.getProperty("basedir", ".");
String karafRoot = basedir + "/target/karaf";
System.setProperty("karaf.root", karafRoot);
System.setProperty("karaf.data", karafRoot + "/data");
sfb = new ZKServerFactoryBean();
delete(sfb.getDataDir());
delete(sfb.getDataLogDir());
sfb.setPort(9123);
sfb.afterPropertiesSet();
int zkPort = sfb.getClientPortAddress().getPort();
LOG.info("Connecting to ZK on port: " + zkPort);
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(360000);
curator = builder.build();
curator.start();
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
// setup a local and remote git repo
File root = new File(basedir + "/target/git").getCanonicalFile();
delete(root);
new File(root, "remote").mkdirs();
remote = Git.init().setDirectory(new File(root, "remote")).setGitDir(new File(root, "remote/.git")).call();
remote.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
String remoteUrl = "file://" + new File(root, "remote").getCanonicalPath();
new File(root, "local").mkdirs();
git = Git.init().setDirectory(new File(root, "local")).setGitDir(new File(root, "local/.git")).call();
git.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
StoredConfig config = git.getRepository().getConfig();
config.setString("remote", "origin", "url", remoteUrl);
config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
config.save();
runtimeProperties = EasyMock.createMock(RuntimeProperties.class);
EasyMock.expect(runtimeProperties.getRuntimeIdentity()).andReturn("root").anyTimes();
EasyMock.expect(runtimeProperties.getHomePath()).andReturn(Paths.get("target")).anyTimes();
EasyMock.expect(runtimeProperties.getDataPath()).andReturn(Paths.get("target/data")).anyTimes();
EasyMock.expect(runtimeProperties.getProperty(EasyMock.eq(SystemProperties.FABRIC_ENVIRONMENT))).andReturn("").anyTimes();
EasyMock.expect(runtimeProperties.removeRuntimeAttribute(DataStoreTemplate.class)).andReturn(null).anyTimes();
EasyMock.replay(runtimeProperties);
FabricGitServiceImpl gitService = new FabricGitServiceImpl();
gitService.bindRuntimeProperties(runtimeProperties);
gitService.activate();
gitService.setGitForTesting(git);
/*
dataStore = new GitDataStoreImpl();
dataStore.bindCurator(curator);
dataStore.bindGitService(gitService);
dataStore.bindRuntimeProperties(runtimeProperties);
dataStore.bindConfigurer(new Configurer() {
@Override
public <T> Map<String, ?> configure(Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
return null;
}
@Override
public <T> Map<String, ?> configure(Dictionary<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
return null;
}
});
Map<String, Object> datastoreProperties = new HashMap<String, Object>();
datastoreProperties.put(GitDataStore.GIT_REMOTE_URL, remoteUrl);
dataStore.activate(datastoreProperties);
*/
fabricService = new FabricServiceImpl();
// fabricService.bindDataStore(dataStore);
fabricService.bindRuntimeProperties(runtimeProperties);
fabricService.bindPlaceholderResolver(new DummyPlaceholerResolver("port"));
fabricService.bindPlaceholderResolver(new DummyPlaceholerResolver("zk"));
fabricService.bindPlaceholderResolver(new ProfilePropertyPointerResolver());
fabricService.bindPlaceholderResolver(new ChecksumPlaceholderResolver());
fabricService.bindPlaceholderResolver(new VersionPropertyPointerResolver());
fabricService.bindPlaceholderResolver(new EnvPlaceholderResolver());
fabricService.activateComponent();
projectDeployer = new ProjectDeployerImpl();
projectDeployer.bindFabricService(fabricService);
projectDeployer.bindMBeanServer(ManagementFactory.getPlatformMBeanServer());
// dataStore.getDefaultVersion();
String defaultVersion = null;
assertEquals("defaultVersion", "1.0", defaultVersion);
// now lets import some data - using the old non-git file layout...
String importPath = basedir + "/../fabric8-karaf/src/main/resources/distro/fabric/import";
assertFolderExists(importPath);
dataStore.importFromFileSystem(importPath);
assertHasVersion(defaultVersion);
}
use of io.fabric8.zookeeper.spring.ZKServerFactoryBean in project fabric8 by jboss-fuse.
the class ManagerTest method testManager.
@Test
public void testManager() throws Exception {
ZKServerFactoryBean zkServerFactoryBean = null;
try {
int zooKeeperPort = getFreePort();
int serverPort = getFreePort();
zkServerFactoryBean = new ZKServerFactoryBean();
zkServerFactoryBean.setPurge(true);
zkServerFactoryBean.setClientPortAddress(new InetSocketAddress("localhost", zooKeeperPort));
zkServerFactoryBean.afterPropertiesSet();
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + zooKeeperPort).retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(60000);
CuratorFramework curator = builder.build();
curator.start();
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
BundleContext bundleContext = createMock(BundleContext.class);
ServiceRegistration registration = createMock(ServiceRegistration.class);
Manager manager = new Manager(bundleContext, curator, "tcp://localhost:" + serverPort, "localhost", TimeUnit.MINUTES.toMillis(5));
bundleContext.addServiceListener(manager, "(service.exported.interfaces=*)");
expect(bundleContext.getProperty("org.osgi.framework.uuid")).andReturn("the-framework-uuid");
expect(bundleContext.registerService(EasyMock.<String[]>anyObject(), same(manager), EasyMock.<Dictionary>same(null))).andReturn(registration);
expect(bundleContext.getServiceReferences((String) null, "(service.exported.interfaces=*)")).andReturn(null);
replay(bundleContext, registration);
manager.init();
verify(bundleContext, registration);
reset(bundleContext, registration);
BundleContext expBundleContext = createMock(BundleContext.class);
Bundle expBundle = createMock(Bundle.class);
ServiceReference reference = createMock(ServiceReference.class);
final Properties props = new Properties();
props.put(Constants.OBJECTCLASS, new String[] { ConfigurationAdmin.class.getName() });
expect(reference.getProperty(EasyMock.<String>anyObject())).andAnswer(new IAnswer<Object>() {
public Object answer() throws Throwable {
return props.get(EasyMock.getCurrentArguments()[0]);
}
}).anyTimes();
expect(reference.getPropertyKeys()).andReturn(props.keySet().toArray(new String[0]));
expect(reference.getBundle()).andReturn(expBundle).anyTimes();
expect(expBundle.getBundleContext()).andReturn(expBundleContext).anyTimes();
expect(expBundle.getState()).andReturn(Bundle.ACTIVE).anyTimes();
replay(bundleContext, registration, reference, expBundleContext, expBundle);
manager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, reference));
Thread.sleep(1000);
verify(bundleContext, registration, reference, expBundleContext, expBundle);
} finally {
try {
zkServerFactoryBean.destroy();
} catch (Throwable t) {
}
}
}
use of io.fabric8.zookeeper.spring.ZKServerFactoryBean in project fabric8 by jboss-fuse.
the class CachingGitDataStoreTest method setUp.
@Before
public void setUp() throws Exception {
sfb = new ZKServerFactoryBean();
delete(sfb.getDataDir());
delete(sfb.getDataLogDir());
sfb.afterPropertiesSet();
runtimeProperties = EasyMock.createMock(RuntimeProperties.class);
EasyMock.expect(runtimeProperties.getRuntimeIdentity()).andReturn("root").anyTimes();
EasyMock.expect(runtimeProperties.getHomePath()).andReturn(Paths.get("target")).anyTimes();
EasyMock.expect(runtimeProperties.getDataPath()).andReturn(Paths.get("target/data")).anyTimes();
EasyMock.expect(runtimeProperties.removeRuntimeAttribute(DataStoreTemplate.class)).andReturn(null).anyTimes();
EasyMock.replay(runtimeProperties);
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + sfb.getClientPortAddress().getPort()).retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(360000);
curator = builder.build();
curator.start();
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
// setup a local and remote git repo
basedir = System.getProperty("basedir", ".");
File root = new File(basedir + "/target/git").getCanonicalFile();
delete(root);
new File(root, "remote").mkdirs();
remote = Git.init().setDirectory(new File(root, "remote")).setGitDir(new File(root, "remote/.git")).call();
remote.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
String remoteUrl = "file://" + new File(root, "remote").getCanonicalPath();
new File(root, "local").mkdirs();
git = Git.init().setDirectory(new File(root, "local")).setGitDir(new File(root, "local/.git")).call();
git.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
StoredConfig config = git.getRepository().getConfig();
config.setString("remote", "origin", "url", remoteUrl);
config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
config.save();
FabricGitServiceImpl gitService = new FabricGitServiceImpl();
gitService.bindRuntimeProperties(runtimeProperties);
gitService.activate();
gitService.setGitForTesting(git);
dataStore = new GitDataStoreImpl();
dataStore.bindCurator(curator);
dataStore.bindGitService(gitService);
dataStore.bindRuntimeProperties(runtimeProperties);
dataStore.bindConfigurer(new Configurer() {
@Override
public <T> Map<String, ?> configure(Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
return null;
}
@Override
public <T> Map<String, ?> configure(Dictionary<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
return null;
}
});
Map<String, Object> datastoreProperties = new HashMap<String, Object>();
// datastoreProperties.put(GitDataStoreImpl.GIT_REMOTE_URL, remoteUrl);
dataStore.activate(datastoreProperties);
}
Aggregations