func TestConnHashTestSuite(t *testing.T) { if testing.Short() { t.Skip("Skipping zk shard test in short mode.") } //launch zk sl := test.NewServiceLauncher() etcdOriPort, stopEtcd, err := sl.Start(test.Etcd) assert.NoError(t, err) s := new(ConnHashTestSuite) s.etcdOriPort = etcdOriPort s.etcdPort = 3333 // used for port forward s.forwarder = portForwarder( fmt.Sprintf(":%d", s.etcdPort), fmt.Sprintf(":%d", s.etcdOriPort)) s.stopForward, err = s.forwarder() assert.NoError(t, err, "no error") // non-forward etcdCli etcdCli = etcd.NewClient([]string{fmt.Sprintf("http://localhost:%d", etcdOriPort)}) // forwardable etcdCli etcdForwdCli = etcd.NewClient([]string{fmt.Sprintf("http://localhost:%d", s.etcdPort)}) suite.Run(t, s) // clean up the forwarding s.stopForward <- struct{}{} etcdCli.Close() etcdForwdCli.Close() assert.NoError(s.T(), stopEtcd()) }
func TestNewLister(t *testing.T) { if testing.Short() { t.Skip("skipping test in short mode.") } // create etcd fmt.Println("starting etcd") srvLaunch := test.NewServiceLauncher() port, stop, err := srvLaunch.Start(test.Etcd) if err != nil { log.Fatalf("etcd failed, %s", err) } assert.NoError(t, err) etcdEnsemble := fmt.Sprintf("http://localhost:%d", port) etcdCli := etcd.NewClient([]string{etcdEnsemble}) assert.NotNil(t, etcdCli) fmt.Println("started etcd") // create config client root := "/root" _, err = etcdCli.SetDir(root, 0) assert.NoError(t, err) _, err = etcdCli.Set(fmt.Sprintf(infoPrefix, root), "{}", 0) assert.NoError(t, err) tcli, err := NewClient(etcdCli, root) cli, ok := tcli.(*clientImpl) assert.True(t, ok) // build file tree _, err = etcdCli.SetDir(filepath.Join(root, "a/b"), 0) assert.NoError(t, err) // create lister ls, err := newLister(cli, "a") assert.NoError(t, err) // add file in dir _, err = etcdCli.Set(fmt.Sprintf(infoPrefix, root), `{"modfiles":[{"op":"A", "path":"a/b/f1"}]}`, 0) assert.NoError(t, err) time.Sleep(time.Second) _, ok = ls.tree["a/b/f1"] assert.True(t, ok) // delete file in dir _, err = etcdCli.Set(fmt.Sprintf(infoPrefix, root), `{"modfiles":[{"op":"D", "path":"a/b/f1"}]}`, 0) assert.NoError(t, err) time.Sleep(time.Second) _, ok = ls.tree["a/b/f1"] assert.False(t, ok) assert.NoError(t, cli.Stop()) assert.NoError(t, stop()) }
func (c *ConfigClientTestSuite) SetupSuite() { fmt.Println("starting etcd") c.srvLaunch = test.NewServiceLauncher() port, stop, err := c.srvLaunch.Start(test.Etcd) c.srvStop = stop c.srvPort = port if err != nil { log.Fatalf("etcd failed, %s", err) } assert.NoError(c.T(), err) etcdEnsemble := fmt.Sprintf("http://localhost:%d", port) c.etcdCli = etcd.NewClient([]string{etcdEnsemble}) assert.NotNil(c.T(), c.etcdCli) fmt.Println("started etcd") }
// SetupSuite setups the testing environment. func (s *ConfigTestSuite) SetupSuite() { var err error s.sl = test.NewServiceLauncher() port, stop, err := s.sl.Start(test.Etcd) s.slStopFunc = stop if err != nil { log.Fatalf("etcd failed, %s", err) } assert.NoError(s.T(), err) etcdEnsemble := fmt.Sprintf("http://localhost:%d", port) s.etcdConn = etcd.NewClient(strings.Split(etcdEnsemble, etcdDelimiter)) assert.NotNil(s.T(), s.etcdConn) promptUser = func(format string, args ...interface{}) { fmt.Printf(format+"\n", args...) s.prompts++ } }
func TestEtcdSuite(t *testing.T) { if testing.Short() { t.Skip("Skipping zk shard test in short mode.") } launcher := test.NewServiceLauncher() defer launcher.StopAll() e := &etcdSuite{} e.testETCD = true e.startFunc = func() (int, error) { port, _, err := launcher.Start(test.Etcd) return port, err } e.stopFunc = func() {} e.newEphemeral = func(port int) (Ephemeral, error) { return NewEtcdEphemeral(etcd.NewClient([]string{fmt.Sprintf("http://localhost:%d", port)})) } fmt.Println("Starting ETCD test suite") suite.Run(t, e) }
func TestZKSuite(t *testing.T) { if testing.Short() { t.Skip("Skipping zk shard test in short mode.") } launcher := test.NewServiceLauncher() z := &zkSuite{} z.testZK = true z.startFunc = func() (int, error) { p, _, e := launcher.Start(test.ZooKeeper) return p, e } z.stopFunc = func() { launcher.StopAll() } z.newEphemeral = func(port int) (Ephemeral, error) { return NewZKEphemeral([]string{fmt.Sprintf(":%d", port)}, ZKRecvTimeout(time.Second)) } fmt.Println("Starting ZK test suite") suite.Run(t, z) }
func run() { sl := test.NewServiceLauncher() defer sl.StopAll() zkPort, _, _ := sl.Start(test.ZooKeeper) fmt.Println(zkPort) redisPort, _, _ := sl.Start(test.Redis) fmt.Println(redisPort) etcdPort, _, _ := sl.Start(test.Etcd) fmt.Println(etcdPort) hbasePort, _, _ := sl.Start(test.HBase) fmt.Println(hbasePort) s := sl.Get(hbasePort) err := s.(test.HbaseService).RunScript(`list`) fmt.Println(err) err = s.(test.HbaseService).RunScriptFromFile("schema.hbase") fmt.Println(err) }