Beispiel #1
0
func TestParallelStore(t *testing.T) {
	defer aostor.FlushLog()
	flag.Parse()
	srv, err := testhlp.StartServer(*hostport)
	if err != nil {
		t.Fatalf("error starting server: %s", err)
	}
	if srv.Close != nil {
		defer srv.Close()
	}
	t.Logf("parallel=%v (%d)", parallel, *parallel)
	urlch := make(chan string)
	if err = testhlp.OneRound(srv.Url, *parallel, *N, urlch, true); err != nil {
		t.Errorf("error while uploading: %s", err)
	}
	if err = testhlp.Shovel(srv.Pid, *hostport); err != nil {
		t.Errorf("error with shovel: %s", err)
	}
}
Beispiel #2
0
func main() {
	defer aostor.FlushLog()
	var pid int
	var hostport string
	var changed bool
	flag.IntVar(&pid, "p", 0, "pid to SIGUSR1 on change")
	flag.StringVar(&hostport, "http", "", "host:port")
	todo_tar := flag.Bool("t", false, "shovel tar to dir")
	todo_realm := flag.String("r", "", "compact realm")
	flag.Parse()

	var onChange aostor.NotifyFunc
	if pid > 0 {
		process, err := os.FindProcess(pid)
		if hostport != "" {
			onChange = func() {
				resp, _ := http.Get("http://" + hostport + "/_signal")
				if resp != nil && resp.Body != nil {
					resp.Body.Close()
				}
			}
		}
		if err != nil {
			logger.Warn("cannot find pid %d: %s", pid, err)
		} else {
			oco := onChange
			onChange = func() {
				process.Signal(syscall.SIGUSR1)
				if oco != nil {
					oco()
				}
			}
		}

	}
	oco := onChange
	onChange = func() {
		changed = true
		if oco != nil {
			oco()
		}
	}

	go func() {
		log.Println(http.ListenAndServe("localhost:6500", nil))
	}()

	if *todo_tar {
		tarfn, dirname := flag.Arg(0), flag.Arg(1)
		if err := aostor.CreateTar(tarfn, dirname, 0, false); err != nil {
			fmt.Printf("ERROR shoveling %s to %s: %s", tarfn, dirname, err)
		} else {
			fmt.Println("OK")
			onChange()
		}
	} else if *todo_realm != "" {
		realm := *todo_realm
		if err := aostor.Compact(realm, onChange); err != nil {
			fmt.Printf("ERROR compacting %s: %s", realm, err)
		} else {
			if changed {
				fmt.Println("no change")
			} else {
				fmt.Println("OK")
			}
		}
	} else {
		fmt.Printf(`Usage:
prg -t tar dir [-p pid]
  or
prg -r realm [-p pid]
`)
	}

	// if *memprofile != "" {
	// 	f, err := os.Create(*memprofile)
	// 	if err != nil {
	// 		log.Fatal(err)
	// 	}
	// 	pprof.WriteHeapProfile(f)
	// 	f.Close()
	// }
}