public MockVoltDB(int clientPort, int adminPort, int httpPort, int drPort) { try { JSONObject obj = new JSONObject(); JSONArray jsonArray = new JSONArray(); jsonArray.put("127.0.0.1"); obj.put("interfaces", jsonArray); obj.put("clientPort", clientPort); obj.put("adminPort", adminPort); obj.put("httpPort", httpPort); obj.put("drPort", drPort); m_localMetadata = obj.toString(4); m_catalog = new Catalog(); m_catalog.execute("add / clusters " + m_clusterName); m_catalog.execute( "add " + m_catalog.getClusters().get(m_clusterName).getPath() + " databases " + m_databaseName); Cluster cluster = m_catalog.getClusters().get(m_clusterName); // Set a sane default for TestMessaging (at least) cluster.setHeartbeattimeout(10000); assert (cluster != null); try { m_hostMessenger.start(); } catch (Exception e) { throw new RuntimeException(e); } VoltZK.createPersistentZKNodes(m_hostMessenger.getZK()); m_hostMessenger .getZK() .create( VoltZK.cluster_metadata + "/" + m_hostMessenger.getHostId(), getLocalMetadata().getBytes("UTF-8"), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); m_hostMessenger.generateMailboxId( m_hostMessenger.getHSIdForLocalSite(HostMessenger.STATS_SITE_ID)); m_statsAgent = new StatsAgent(); m_statsAgent.registerMailbox( m_hostMessenger, m_hostMessenger.getHSIdForLocalSite(HostMessenger.STATS_SITE_ID)); for (MailboxType type : MailboxType.values()) { m_mailboxMap.put(type, new LinkedList<MailboxNodeContent>()); } m_mailboxMap .get(MailboxType.StatsAgent) .add( new MailboxNodeContent( m_hostMessenger.getHSIdForLocalSite(HostMessenger.STATS_SITE_ID), null)); m_siteTracker = new SiteTracker(m_hostId, m_mailboxMap); } catch (Exception e) { throw new RuntimeException(e); } }
public JoinCoordinator(HostMessenger hostMessenger) { super(hostMessenger, hostMessenger.generateMailboxId(null)); m_messenger = hostMessenger; }