MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / initNode

Function initNode

worker/helper_test.go:186–241  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

184}
185
186func initNode() (cleanupFunc func(), server *rpc.Server, err error) {
187 var d string
188 if d, err = ioutil.TempDir("", "db_test_"); err != nil {
189 return
190 }
191
192 // init conf
193 _, testFile, _, _ := runtime.Caller(0)
194 pubKeyStoreFile := filepath.Join(d, PubKeyStorePath)
195 utils.RemoveAll(pubKeyStoreFile + "*")
196 clientPubKeyStoreFile := filepath.Join(d, PubKeyStorePath+"_c")
197 utils.RemoveAll(clientPubKeyStoreFile + "*")
198 dupConfFile := filepath.Join(d, "config.yaml")
199 confFile := filepath.Join(filepath.Dir(testFile), "../test/node_standalone/config.yaml")
200 if err = utils.DupConf(confFile, dupConfFile); err != nil {
201 return
202 }
203 privateKeyPath := filepath.Join(filepath.Dir(testFile), "../test/node_standalone/private.key")
204
205 conf.GConf, _ = conf.LoadConfig(dupConfFile)
206 // reset the once
207 route.Once.Reset()
208 route.InitKMS(clientPubKeyStoreFile)
209
210 var dht *route.DHTService
211
212 // init dht
213 dht, err = route.NewDHTService(pubKeyStoreFile, new(consistent.KMSStorage), true)
214 if err != nil {
215 return
216 }
217
218 // init rpc
219 if server, err = rpc.NewServerWithService(rpc.ServiceMap{route.DHTRPCName: dht}); err != nil {
220 return
221 }
222
223 // init private key
224 masterKey := []byte("")
225 if err = server.InitRPCServer(conf.GConf.ListenAddr, privateKeyPath, masterKey); err != nil {
226 return
227 }
228
229 // start server
230 go server.Serve()
231
232 cleanupFunc = func() {
233 os.RemoveAll(d)
234 server.Listener.Close()
235 server.Stop()
236 // clear the connection pool
237 rpc.GetSessionPoolInstance().Close()
238 }
239
240 return
241}

Callers 4

TestSingleDatabaseFunction · 0.70
TestInitFailedFunction · 0.70
TestDatabaseRecycleFunction · 0.70
TestDBMSFunction · 0.70

Calls 10

RemoveAllFunction · 0.92
DupConfFunction · 0.92
LoadConfigFunction · 0.92
InitKMSFunction · 0.92
NewDHTServiceFunction · 0.92
InitRPCServerMethod · 0.80
ResetMethod · 0.65
CloseMethod · 0.65
ServeMethod · 0.45
StopMethod · 0.45

Tested by

no test coverage detected