reflector.go/cmd/test.go

55 lines
1.1 KiB
Go
Raw Normal View History

2018-09-01 01:50:22 +02:00
package cmd
import (
2019-01-29 20:28:40 +01:00
"os"
"os/signal"
"strconv"
"syscall"
"time"
"github.com/lbryio/reflector.go/meta"
"github.com/lbryio/reflector.go/peer"
"github.com/lbryio/reflector.go/reflector"
"github.com/lbryio/reflector.go/store"
"github.com/davecgh/go-spew/spew"
2018-09-11 13:41:29 +02:00
log "github.com/sirupsen/logrus"
2018-09-01 01:50:22 +02:00
"github.com/spf13/cobra"
)
func init() {
var cmd = &cobra.Command{
Use: "test",
Short: "Test things",
Run: testCmd,
}
rootCmd.AddCommand(cmd)
}
func testCmd(cmd *cobra.Command, args []string) {
2019-01-29 20:28:40 +01:00
log.Printf("reflector version %s", meta.Version)
memStore := &store.MemoryBlobStore{}
reflectorServer := reflector.NewServer(memStore)
reflectorServer.Timeout = 3 * time.Minute
err := reflectorServer.Start(":" + strconv.Itoa(reflector.DefaultPort))
if err != nil {
log.Fatal(err)
}
peerServer := peer.NewServer(memStore)
err = peerServer.Start(":" + strconv.Itoa(reflector.DefaultPort+1))
2019-01-29 20:28:40 +01:00
if err != nil {
log.Fatal(err)
}
interruptChan := make(chan os.Signal, 1)
signal.Notify(interruptChan, os.Interrupt, syscall.SIGTERM)
<-interruptChan
peerServer.Shutdown()
reflectorServer.Shutdown()
spew.Dump(memStore)
2018-09-01 01:50:22 +02:00
}