本文整理匯總了Golang中github.com/mesos/mesos-go/upid.Parse函數的典型用法代碼示例。如果您正苦於以下問題:Golang Parse函數的具體用法?Golang Parse怎麽用?Golang Parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Parse函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestSchedCachePutOffer
func TestSchedCachePutOffer(t *testing.T) {
cache := newSchedCache()
offer01 := createTestOffer("01")
pid01, err := upid.Parse("[email protected]:5050")
assert.NoError(t, err)
cache.putOffer(offer01, pid01)
offer02 := createTestOffer("02")
pid02, err := upid.Parse("[email protected]:5050")
assert.NoError(t, err)
cache.putOffer(offer02, pid02)
assert.Equal(t, len(cache.savedOffers), 2)
cachedOffer1, ok := cache.savedOffers["test-offer-01"]
assert.True(t, ok)
cachedOffer2, ok := cache.savedOffers["test-offer-02"]
assert.True(t, ok)
assert.NotNil(t, cachedOffer1.offer)
assert.Equal(t, "test-offer-01", cachedOffer1.offer.Id.GetValue())
assert.NotNil(t, cachedOffer2.offer)
assert.Equal(t, "test-offer-02", cachedOffer2.offer.Id.GetValue())
assert.NotNil(t, cachedOffer1.slavePid)
assert.Equal(t, "[email protected]:5050", cachedOffer1.slavePid.String())
assert.NotNil(t, cachedOffer2.slavePid)
assert.Equal(t, "[email protected]:5050", cachedOffer2.slavePid.String())
}
示例2: TestSchedCachePutSlavePid
func TestSchedCachePutSlavePid(t *testing.T) {
cache := newSchedCache()
pid01, err := upid.Parse("[email protected]:5050")
assert.NoError(t, err)
pid02, err := upid.Parse("[email protected]:5050")
assert.NoError(t, err)
pid03, err := upid.Parse("[email protected]:5050")
assert.NoError(t, err)
cache.putSlavePid(util.NewSlaveID("slave01"), pid01)
cache.putSlavePid(util.NewSlaveID("slave02"), pid02)
cache.putSlavePid(util.NewSlaveID("slave03"), pid03)
assert.Equal(t, len(cache.savedSlavePids), 3)
cachedSlavePid1, ok := cache.savedSlavePids["slave01"]
assert.True(t, ok)
cachedSlavePid2, ok := cache.savedSlavePids["slave02"]
assert.True(t, ok)
cachedSlavePid3, ok := cache.savedSlavePids["slave03"]
assert.True(t, ok)
assert.True(t, cachedSlavePid1.Equal(pid01))
assert.True(t, cachedSlavePid2.Equal(pid02))
assert.True(t, cachedSlavePid3.Equal(pid03))
}
示例3: BenchmarkMessengerSendRecvMixedMessage
func BenchmarkMessengerSendRecvMixedMessage(b *testing.B) {
globalWG.Add(b.N)
messages := generateMixedMessages(1000)
upid1, err := upid.Parse(fmt.Sprintf("[email protected]:%d", getNewPort()))
assert.NoError(b, err)
upid2, err := upid.Parse(fmt.Sprintf("[email protected]:%d", getNewPort()))
assert.NoError(b, err)
m1 := NewHttp(upid1)
m2 := NewHttp(upid2)
assert.NoError(b, m1.Start())
assert.NoError(b, m2.Start())
assert.NoError(b, m2.Install(noopHandler, &testmessage.SmallMessage{}))
assert.NoError(b, m2.Install(noopHandler, &testmessage.MediumMessage{}))
assert.NoError(b, m2.Install(noopHandler, &testmessage.BigMessage{}))
assert.NoError(b, m2.Install(noopHandler, &testmessage.LargeMessage{}))
time.Sleep(time.Second) // Avoid race on upid.
b.ResetTimer()
for i := 0; i < b.N; i++ {
m1.Send(context.TODO(), upid2, messages[i%1000])
}
globalWG.Wait()
}
示例4: TestTransporterStartAndRcvd
func TestTransporterStartAndRcvd(t *testing.T) {
serverId := "testserver"
serverPort := getNewPort()
serverAddr := "127.0.0.1:" + strconv.Itoa(serverPort)
protoMsg := testmessage.GenerateSmallMessage()
msgName := getMessageName(protoMsg)
ctrl := make(chan struct{})
// setup receiver (server) process
rcvPid, err := upid.Parse(fmt.Sprintf("%[email protected]%s", serverId, serverAddr))
assert.NoError(t, err)
receiver := NewHTTPTransporter(rcvPid, nil)
receiver.Install(msgName)
go func() {
defer close(ctrl)
msg, err := receiver.Recv()
assert.Nil(t, err)
assert.NotNil(t, msg)
if msg != nil {
assert.Equal(t, msgName, msg.Name)
}
}()
errch := receiver.Start()
defer receiver.Stop(false)
assert.NotNil(t, errch)
time.Sleep(time.Millisecond * 7) // time to catchup
// setup sender (client) process
sndUpid, err := upid.Parse(fmt.Sprintf("[email protected]:%d", getNewPort()))
assert.NoError(t, err)
sender := NewHTTPTransporter(sndUpid, nil)
msg := &Message{
UPID: rcvPid,
Name: msgName,
ProtoMessage: protoMsg,
}
errch2 := sender.Start()
defer sender.Stop(false)
sender.Send(context.TODO(), msg)
select {
case <-time.After(time.Second * 5):
t.Fatalf("Timeout")
case <-ctrl:
case err := <-errch:
if err != nil {
t.Fatalf(err.Error())
}
case err := <-errch2:
if err != nil {
t.Fatalf(err.Error())
}
}
}
示例5: getLibprocessFrom
func getLibprocessFrom(r *http.Request) (*upid.UPID, error) {
if r.Method != "POST" {
return nil, fmt.Errorf("Not a POST request")
}
if agent, ok := parseLibprocessAgent(r.Header); ok {
return upid.Parse(agent)
}
lf, ok := r.Header["Libprocess-From"]
if ok {
// TODO(yifan): Just take the first field for now.
return upid.Parse(lf[0])
}
return nil, fmt.Errorf("Cannot find 'User-Agent' or 'Libprocess-From'")
}
示例6: TestSchedCacheContainsSlavePid
func TestSchedCacheContainsSlavePid(t *testing.T) {
cache := newSchedCache()
pid01, err := upid.Parse("[email protected]:5050")
assert.NoError(t, err)
pid02, err := upid.Parse("[email protected]:5050")
assert.NoError(t, err)
cache.putSlavePid(util.NewSlaveID("slave01"), pid01)
cache.putSlavePid(util.NewSlaveID("slave02"), pid02)
assert.True(t, cache.containsSlavePid(util.NewSlaveID("slave01")))
assert.True(t, cache.containsSlavePid(util.NewSlaveID("slave02")))
assert.False(t, cache.containsSlavePid(util.NewSlaveID("slave05")))
}
示例7: _fetchPid
// assumes that address is in host:port format
func (s *Standalone) _fetchPid(ctx context.Context, address string) (*upid.UPID, error) {
//TODO(jdef) need SSL support
uri := fmt.Sprintf("http://%s/state", address)
req, err := http.NewRequest("GET", uri, nil)
if err != nil {
return nil, err
}
var pid *upid.UPID
err = s.httpDo(ctx, req, func(res *http.Response, err error) error {
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode != 200 {
return fmt.Errorf("HTTP request failed with code %d: %v", res.StatusCode, res.Status)
}
blob, err1 := ioutil.ReadAll(res.Body)
if err1 != nil {
return err1
}
log.V(3).Infof("Got mesos state, content length %v", len(blob))
type State struct {
Leader string `json:"leader"` // ex: master(1)@10.22.211.18:5050
}
state := &State{}
err = json.Unmarshal(blob, state)
if err != nil {
return err
}
pid, err = upid.Parse(state.Leader)
return err
})
return pid, err
}
示例8: TestMutatedHostUPid
func TestMutatedHostUPid(t *testing.T) {
serverId := "testserver"
// NOTE(tsenart): This static port can cause conflicts if multiple instances
// of this test run concurrently or else if this port is already bound by
// another socket.
serverPort := 12345
serverHost := "127.0.0.1"
serverAddr := serverHost + ":" + strconv.Itoa(serverPort)
// override the upid.Host with this listener IP
addr := net.ParseIP("0.0.0.0")
// setup receiver (server) process
uPid, err := upid.Parse(fmt.Sprintf("%[email protected]%s", serverId, serverAddr))
assert.NoError(t, err)
receiver := NewHTTPTransporter(*uPid, addr)
err = receiver.listen()
assert.NoError(t, err)
if receiver.upid.Host != "127.0.0.1" {
t.Fatalf("reciever.upid.Host was expected to return %s, got %s\n", serverHost, receiver.upid.Host)
}
if receiver.upid.Port != strconv.Itoa(serverPort) {
t.Fatalf("receiver.upid.Port was expected to return %d, got %s\n", serverPort, receiver.upid.Port)
}
}
示例9: TestMessengerFailToSend
func TestMessengerFailToSend(t *testing.T) {
upid, err := upid.Parse(fmt.Sprintf("[email protected]ocalhost:%d", getNewPort()))
assert.NoError(t, err)
m := NewHttp(upid)
assert.NoError(t, m.Start())
assert.Error(t, m.Send(context.TODO(), upid, &testmessage.SmallMessage{}))
}
示例10: TestEmptyHostPortUPid
func TestEmptyHostPortUPid(t *testing.T) {
serverId := "testserver"
serverPort := getNewPort()
serverHost := "127.0.0.1"
serverAddr := serverHost + ":" + strconv.Itoa(serverPort)
// setup receiver (server) process
uPid, err := upid.Parse(fmt.Sprintf("%[email protected]%s", serverId, serverAddr))
assert.NoError(t, err)
// Unset upid host and port
uPid.Host = ""
uPid.Port = ""
// override the upid.Host with this listener IP
addr := net.ParseIP("127.0.0.2")
receiver := NewHTTPTransporter(uPid, addr)
err = receiver.listen()
assert.NoError(t, err)
// This should be the host that overrides as uPid.Host is empty
if receiver.upid.Host != "127.0.0.2" {
t.Fatalf("reciever.upid.Host was expected to return %s, got %s\n", serverHost, receiver.upid.Host)
}
// This should end up being a random port, not the server port as uPid
// port is empty
if receiver.upid.Port == strconv.Itoa(serverPort) {
t.Fatalf("receiver.upid.Port was not expected to return %d, got %s\n", serverPort, receiver.upid.Port)
}
}
示例11: TestSlaveHealthCheckerFailedOnBlockedSlave
func TestSlaveHealthCheckerFailedOnBlockedSlave(t *testing.T) {
s := newBlockedServer(5)
ts := httptest.NewUnstartedServer(s)
ts.Start()
defer ts.Close()
defer s.stop()
upid, err := upid.Parse(fmt.Sprintf("[email protected]%s", ts.Listener.Addr().String()))
assert.NoError(t, err)
checker := NewSlaveHealthChecker(upid, 10, time.Millisecond*10, time.Millisecond*10)
ch := checker.Start()
defer checker.Stop()
select {
case <-time.After(time.Second):
t.Error("timeout")
case <-ch:
assert.True(t, atomic.LoadInt32(&s.th.cnt) > 10)
}
// TODO(jdef) hack: this sucks, but there's a data race in httptest's handler when Close()
// and ServeHTTP() are invoked (WaitGroup DATA RACE). Sleeping here to attempt to avoid that.
// I think this is supposed to be fixed in go1.6
time.Sleep(5 * time.Second)
}
示例12: TestSchedCacheContainsOffer
func TestSchedCacheContainsOffer(t *testing.T) {
cache := newSchedCache()
offer01 := createTestOffer("01")
pid01, err := upid.Parse("[email protected]:5050")
assert.NoError(t, err)
offer02 := createTestOffer("02")
pid02, err := upid.Parse("[email protected]:5050")
assert.NoError(t, err)
cache.putOffer(offer01, pid01)
cache.putOffer(offer02, pid02)
assert.True(t, cache.containsOffer(util.NewOfferID("test-offer-01")))
assert.True(t, cache.containsOffer(util.NewOfferID("test-offer-02")))
assert.False(t, cache.containsOffer(util.NewOfferID("test-offer-05")))
}
示例13: resourcesOffered
func (driver *MesosSchedulerDriver) resourcesOffered(from *upid.UPID, pbMsg proto.Message) {
log.V(2).Infoln("Handling resource offers.")
msg := pbMsg.(*mesos.ResourceOffersMessage)
if driver.status == mesos.Status_DRIVER_ABORTED {
log.Infoln("Ignoring ResourceOffersMessage, the driver is aborted!")
return
}
if !driver.connected {
log.Infoln("Ignoring ResourceOffersMessage, the driver is not connected!")
return
}
pidStrings := msg.GetPids()
if len(pidStrings) != len(msg.Offers) {
log.Errorln("Ignoring offers, Offer count does not match Slave PID count.")
return
}
for i, offer := range msg.Offers {
if pid, err := upid.Parse(pidStrings[i]); err == nil {
driver.cache.putOffer(offer, pid)
log.V(2).Infof("Cached offer %s from SlavePID %s", offer.Id.GetValue(), pid)
} else {
log.Warningf("Failed to parse offer PID '%v': %v", pid, err)
}
}
driver.withScheduler(func(s Scheduler) { s.ResourceOffers(driver, msg.Offers) })
}
示例14: TestSlaveHealthCheckerPartitonedSlave
func TestSlaveHealthCheckerPartitonedSlave(t *testing.T) {
t.Skip("skipping known flaky test (fails on busy CI servers, should use a fake clock)")
s := newPartitionedServer(5, 9)
ts := httptest.NewUnstartedServer(s)
ts.Start()
defer ts.Close()
t.Log("test server listening on", ts.Listener.Addr())
upid, err := upid.Parse(fmt.Sprintf("[email protected]%s", ts.Listener.Addr().String()))
assert.NoError(t, err)
checker := NewSlaveHealthChecker(upid, 10, time.Millisecond*10, time.Millisecond*10)
ch := checker.Start()
defer func() {
checker.Stop()
<-checker.stop
}()
select {
case <-time.After(2 * time.Second):
actual := atomic.LoadInt32(&checker.continuousUnhealthyCount)
assert.EqualValues(t, 0, actual, "expected 0 unhealthy counts instead of %d", actual)
case <-ch:
t.Fatal("Shouldn't get unhealthy notification")
}
}
示例15: TestMutatedHostUPid
func TestMutatedHostUPid(t *testing.T) {
serverId := "testserver"
serverPort := getNewPort()
serverHost := "127.0.0.1"
serverAddr := serverHost + ":" + strconv.Itoa(serverPort)
// override the upid.Host with this listener IP
addr := net.ParseIP("127.0.0.2")
// setup receiver (server) process
uPid, err := upid.Parse(fmt.Sprintf("%[email protected]%s", serverId, serverAddr))
assert.NoError(t, err)
receiver := NewHTTPTransporter(uPid, addr)
err = receiver.listen()
assert.NoError(t, err)
if receiver.upid.Host != "127.0.0.1" {
t.Fatalf("reciever.upid.Host was expected to return %s, got %s\n", serverHost, receiver.upid.Host)
}
if receiver.upid.Port != strconv.Itoa(serverPort) {
t.Fatalf("receiver.upid.Port was expected to return %d, got %s\n", serverPort, receiver.upid.Port)
}
}