This repository has been archived by the owner on Dec 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
921 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package server | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/mosuka/blast/log" | ||
"github.com/mosuka/blast/util" | ||
) | ||
|
||
func Test_GRPCGateway_Start_Stop(t *testing.T) { | ||
httpAddress := fmt.Sprintf(":%d", util.TmpPort()) | ||
grpcAddress := fmt.Sprintf(":%d", util.TmpPort()) | ||
certificateFile := "" | ||
KeyFile := "" | ||
commonName := "" | ||
corsAllowedMethods := make([]string, 0) | ||
corsAllowedOrigins := make([]string, 0) | ||
corsAllowedHeaders := make([]string, 0) | ||
logger := log.NewLogger("WARN", "", 500, 3, 30, false) | ||
|
||
grpcGateway, err := NewGRPCGateway(httpAddress, grpcAddress, certificateFile, KeyFile, commonName, corsAllowedMethods, corsAllowedOrigins, corsAllowedHeaders, logger) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
defer func() { | ||
if err := grpcGateway.Stop(); err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
}() | ||
|
||
if err := grpcGateway.Start(); err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
||
time.Sleep(3 * time.Second) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package server | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/mosuka/blast/log" | ||
"github.com/mosuka/blast/mapping" | ||
"github.com/mosuka/blast/util" | ||
) | ||
|
||
func Test_GRPCServer_Start_Stop(t *testing.T) { | ||
curDir, err := os.Getwd() | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
||
tmpDir := util.TmpDir() | ||
defer func() { | ||
_ = os.RemoveAll(tmpDir) | ||
}() | ||
|
||
logger := log.NewLogger("WARN", "", 500, 3, 30, false) | ||
|
||
// Raft server | ||
rafAddress := fmt.Sprintf(":%d", util.TmpPort()) | ||
dir := util.TmpDir() | ||
defer func() { | ||
_ = os.RemoveAll(dir) | ||
}() | ||
indexMapping, err := mapping.NewIndexMappingFromFile(filepath.Join(curDir, "../examples/example_mapping.json")) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
raftServer, err := NewRaftServer("node1", rafAddress, dir, indexMapping, true, logger) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
defer func() { | ||
if err := raftServer.Stop(); err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
}() | ||
if err := raftServer.Start(); err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
||
// gRPC server | ||
grpcAddress := fmt.Sprintf(":%d", util.TmpPort()) | ||
certificateFile := "" | ||
keyFile := "" | ||
commonName := "" | ||
|
||
grpcServer, err := NewGRPCServer(grpcAddress, raftServer, certificateFile, keyFile, commonName, logger) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
defer func() { | ||
if err := grpcServer.Stop(); err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
}() | ||
|
||
if err := grpcServer.Start(); err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
||
time.Sleep(3 * time.Second) | ||
} |
Oops, something went wrong.