本文整理汇总了Golang中Time.Unix函数的典型用法代码示例。如果您正苦于以下问题:Golang Unix函数的具体用法?Golang Unix怎么用?Golang Unix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Unix函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestFileStore_Read
func TestFileStore_Read(t *testing.T) {
fs := tsm1.NewFileStore("")
// Setup 3 files
data := []keyValues{
keyValues{"cpu", []tsm1.Value{tsm1.NewValue(time.Unix(0, 0), 1.0)}},
keyValues{"cpu", []tsm1.Value{tsm1.NewValue(time.Unix(1, 0), 2.0)}},
keyValues{"mem", []tsm1.Value{tsm1.NewValue(time.Unix(0, 0), 1.0)}},
}
files, err := newFiles(data...)
if err != nil {
t.Fatalf("unexpected error creating files: %v", err)
}
fs.Add(files...)
// Search for an entry that exists in the second file
values, err := fs.Read("cpu", time.Unix(1, 0))
if err != nil {
t.Fatalf("unexpected error reading values: %v", err)
}
exp := data[1]
if got, exp := len(values), len(exp.values); got != exp {
t.Fatalf("value length mismatch: got %v, exp %v", got, exp)
}
for i, v := range exp.values {
if got, exp := values[i].Value(), v.Value(); got != exp {
t.Fatalf("read value mismatch(%d): got %v, exp %d", i, got, exp)
}
}
}
示例2: XXXTestBulkErrors
func XXXTestBulkErrors(t *testing.T) {
// lets set a bad port, and hope we get a conn refused error?
c := NewTestConn()
c.Port = "27845"
defer func() {
c.Port = "9200"
}()
indexer := c.NewBulkIndexerErrors(10, 1)
indexer.Start()
errorCt := 0
go func() {
for i := 0; i < 20; i++ {
date := time.Unix(1257894000, 0)
data := map[string]interface{}{"name": "smurfs", "age": 22, "date": time.Unix(1257894000, 0)}
indexer.Index("users", "user", strconv.Itoa(i), "", &date, data, true)
}
}()
var errBuf *ErrorBuffer
for errBuf = range indexer.ErrorChannel {
errorCt++
break
}
if errBuf.Buf.Len() > 0 {
gou.Debug(errBuf.Err)
}
assert.T(t, errorCt > 0, fmt.Sprintf("ErrorCt should be > 0 %d", errorCt))
indexer.Stop()
}
示例3: TestAction
func TestAction(t *testing.T) {
action := NewAction(false, "Something")
action.End = now + 20
Convey("Get right start date", t, func() {
expectedStart := time.Unix(now, 0).Format(DateFormat)
So(action.GetStartDate(), ShouldEqual, expectedStart)
})
Convey("Get right end date", t, func() {
expectedEnd := time.Unix(now+20, 0).Format(DateFormat)
So(action.GetEndDate(), ShouldEqual, expectedEnd)
})
Convey("Get end date for a process which is not finished", t, func() {
action.End = 0
So(action.GetEndDate(), ShouldEqual, "Not yet")
})
Convey("right result", t, func() {
action.ChangeResult("danger")
So(action.GetResult(), ShouldEqual, "danger")
})
Convey("Complete example", t, func() {
action2 := &Action{
Start: now,
End: 0,
}
So(action.GetEndDate(), ShouldEqual, "Not yet")
action2.ChangeResult("warning")
action2.Finish()
So(action.IsRunning, ShouldBeFalse)
})
}
示例4: TestCRLCreation
func TestCRLCreation(t *testing.T) {
block, _ := pem.Decode([]byte(pemPrivateKey))
priv, _ := ParsePKCS1PrivateKey(block.Bytes)
block, _ = pem.Decode([]byte(pemCertificate))
cert, _ := ParseCertificate(block.Bytes)
now := time.Unix(1000, 0)
expiry := time.Unix(10000, 0)
revokedCerts := []pkix.RevokedCertificate{
{
SerialNumber: big.NewInt(1),
RevocationTime: now,
},
{
SerialNumber: big.NewInt(42),
RevocationTime: now,
},
}
crlBytes, err := cert.CreateCRL(rand.Reader, priv, revokedCerts, now, expiry)
if err != nil {
t.Errorf("error creating CRL: %s", err)
}
_, err = ParseDERCRL(crlBytes)
if err != nil {
t.Errorf("error reparsing CRL: %s", err)
}
}
示例5: getStartAndEndBasedOnDuration
func (self *ClusterConfiguration) getStartAndEndBasedOnDuration(microsecondsEpoch int64, duration float64) (*time.Time, *time.Time) {
startTimeSeconds := math.Floor(float64(microsecondsEpoch)/1000.0/1000.0/duration) * duration
startTime := time.Unix(int64(startTimeSeconds), 0)
endTime := time.Unix(int64(startTimeSeconds+duration), 0)
return &startTime, &endTime
}
示例6: GetFirstTimestamp
// GetFirstTimestamp returns the timestamp of the first packet
func GetFirstTimestamp(filepath string) (*time.Time, error) {
data, err := readHeaders(filepath)
if err != nil {
return nil, err
}
typ, e, err := isPcap(data)
if err != nil {
return nil, err
} else if typ == INVALID || typ == PCAP_NG {
return nil, errors.New("not a valid pcap")
}
if len(data) < 24+4 {
return nil, errors.New("no packet the in pcap")
}
if e == LITTLE {
i := binary.LittleEndian.Uint32(data[24 : 24+4]) // access to ts_sec; in the first packet's heade
t := time.Unix((int64)(i), 0)
return &t, nil
} else {
i := binary.BigEndian.Uint32(data[24 : 24+4]) // access to ts_sec; in the first packet's heade
t := time.Unix((int64)(i), 0)
return &t, nil
}
}
示例7: NewRetentionPolicy
func NewRetentionPolicy(name string, duration time.Duration, nodeCount int) *meta.RetentionPolicyInfo {
shards := []meta.ShardInfo{}
owners := []meta.ShardOwner{}
for i := 1; i <= nodeCount; i++ {
owners = append(owners, meta.ShardOwner{NodeID: uint64(i)})
}
// each node is fully replicated with each other
shards = append(shards, meta.ShardInfo{
ID: nextShardID(),
Owners: owners,
})
rp := &meta.RetentionPolicyInfo{
Name: "myrp",
ReplicaN: nodeCount,
Duration: duration,
ShardGroupDuration: duration,
ShardGroups: []meta.ShardGroupInfo{
meta.ShardGroupInfo{
ID: nextShardID(),
StartTime: time.Unix(0, 0),
EndTime: time.Unix(0, 0).Add(duration).Add(-1),
Shards: shards,
},
},
}
return rp
}
示例8: TestParsePointEscapedStringsAndCommas
func TestParsePointEscapedStringsAndCommas(t *testing.T) {
// non-escaped comma and quotes
test(t, `cpu,host=serverA,region=us-east value="{Hello\"{,}\" World}" 1000000000`,
tsdb.NewPoint(
"cpu",
tsdb.Tags{
"host": "serverA",
"region": "us-east",
},
tsdb.Fields{
"value": `{Hello"{,}" World}`,
},
time.Unix(1, 0)),
)
// escaped comma and quotes
test(t, `cpu,host=serverA,region=us-east value="{Hello\"{\,}\" World}" 1000000000`,
tsdb.NewPoint(
"cpu",
tsdb.Tags{
"host": "serverA",
"region": "us-east",
},
tsdb.Fields{
"value": `{Hello"{\,}" World}`,
},
time.Unix(1, 0)),
)
}
示例9: TestNewPointNaN
func TestNewPointNaN(t *testing.T) {
test(t, `cpu value=NaN 1000000000`,
tsdb.NewPoint(
"cpu",
tsdb.Tags{},
tsdb.Fields{
"value": math.NaN(),
},
time.Unix(1, 0)),
)
test(t, `cpu value=nAn 1000000000`,
tsdb.NewPoint(
"cpu",
tsdb.Tags{},
tsdb.Fields{
"value": math.NaN(),
},
time.Unix(1, 0)),
)
test(t, `nan value=NaN`,
tsdb.NewPoint(
"nan",
tsdb.Tags{},
tsdb.Fields{
"value": math.NaN(),
},
time.Unix(0, 0)),
)
}
示例10: TestParsePointWithStringField
func TestParsePointWithStringField(t *testing.T) {
test(t, `cpu,host=serverA,region=us-east value=1.0,str="foo",str2="bar" 1000000000`,
tsdb.NewPoint("cpu",
tsdb.Tags{
"host": "serverA",
"region": "us-east",
},
tsdb.Fields{
"value": 1.0,
"str": "foo",
"str2": "bar",
},
time.Unix(1, 0)),
)
test(t, `cpu,host=serverA,region=us-east str="foo \" bar" 1000000000`,
tsdb.NewPoint("cpu",
tsdb.Tags{
"host": "serverA",
"region": "us-east",
},
tsdb.Fields{
"str": `foo " bar`,
},
time.Unix(1, 0)),
)
}
示例11: TestParsePointWithStringWithCommas
func TestParsePointWithStringWithCommas(t *testing.T) {
// escaped comma
test(t, `cpu,host=serverA,region=us-east value=1.0,str="foo\,bar" 1000000000`,
tsdb.NewPoint(
"cpu",
tsdb.Tags{
"host": "serverA",
"region": "us-east",
},
tsdb.Fields{
"value": 1.0,
"str": `foo\,bar`, // commas in string value
},
time.Unix(1, 0)),
)
// non-escaped comma
test(t, `cpu,host=serverA,region=us-east value=1.0,str="foo,bar" 1000000000`,
tsdb.NewPoint(
"cpu",
tsdb.Tags{
"host": "serverA",
"region": "us-east",
},
tsdb.Fields{
"value": 1.0,
"str": "foo,bar", // commas in string value
},
time.Unix(1, 0)),
)
}
示例12: ParseAddr
// Parese network's "addr" message
func ParseAddr(pl []byte) {
b := bytes.NewBuffer(pl)
cnt, _ := btc.ReadVLen(b)
for i := 0; i < int(cnt); i++ {
var buf [30]byte
n, e := b.Read(buf[:])
if n != len(buf) || e != nil {
common.CountSafe("AddrError")
//println("ParseAddr:", n, e)
break
}
a := NewPeer(buf[:])
if !ValidIp4(a.Ip4[:]) {
common.CountSafe("AddrInvalid")
} else if time.Unix(int64(a.Time), 0).Before(time.Now().Add(time.Minute)) {
if time.Now().Before(time.Unix(int64(a.Time), 0).Add(ExpirePeerAfter)) {
k := qdb.KeyType(a.UniqID())
v := PeerDB.Get(k)
if v != nil {
a.Banned = NewPeer(v[:]).Banned
}
PeerDB.Put(k, a.Bytes())
} else {
common.CountSafe("AddrStale")
}
} else {
common.CountSafe("AddrInFuture")
}
}
}
示例13: TestFileStore_Open
func TestFileStore_Open(t *testing.T) {
dir := MustTempDir()
defer os.RemoveAll(dir)
// Create 3 TSM files...
data := []keyValues{
keyValues{"cpu", []tsm1.Value{tsm1.NewValue(time.Unix(0, 0), 1.0)}},
keyValues{"cpu", []tsm1.Value{tsm1.NewValue(time.Unix(1, 0), 2.0)}},
keyValues{"mem", []tsm1.Value{tsm1.NewValue(time.Unix(0, 0), 1.0)}},
}
_, err := newFileDir(dir, data...)
if err != nil {
fatal(t, "creating test files", err)
}
fs := tsm1.NewFileStore(dir)
if err := fs.Open(); err != nil {
fatal(t, "opening file store", err)
}
defer fs.Close()
if got, exp := fs.Count(), 3; got != exp {
t.Fatalf("file count mismatch: got %v, exp %v", got, exp)
}
if got, exp := fs.CurrentID(), 4; got != exp {
t.Fatalf("current ID mismatch: got %v, exp %v", got, exp)
}
}
示例14: TestFileStore_Delete
func TestFileStore_Delete(t *testing.T) {
fs := tsm1.NewFileStore("")
// Setup 3 files
data := []keyValues{
keyValues{"cpu,host=server2!~#!value", []tsm1.Value{tsm1.NewValue(time.Unix(0, 0), 1.0)}},
keyValues{"cpu,host=server1!~#!value", []tsm1.Value{tsm1.NewValue(time.Unix(1, 0), 2.0)}},
keyValues{"mem,host=server1!~#!value", []tsm1.Value{tsm1.NewValue(time.Unix(0, 0), 1.0)}},
}
files, err := newFiles(data...)
if err != nil {
t.Fatalf("unexpected error creating files: %v", err)
}
fs.Add(files...)
keys := fs.Keys()
if got, exp := len(keys), 3; got != exp {
t.Fatalf("key length mismatch: got %v, exp %v", got, exp)
}
if err := fs.Delete("cpu,host=server2!~#!value"); err != nil {
fatal(t, "deleting", err)
}
keys = fs.Keys()
if got, exp := len(keys), 2; got != exp {
t.Fatalf("key length mismatch: got %v, exp %v", got, exp)
}
}
示例15: TestEngine_WritePoints_PointsWriter
// Ensure the engine can write points to storage.
func TestEngine_WritePoints_PointsWriter(t *testing.T) {
e := OpenDefaultEngine()
defer e.Close()
// Points to be inserted.
points := []models.Point{
models.NewPoint("cpu", models.Tags{}, models.Fields{}, time.Unix(0, 1)),
models.NewPoint("cpu", models.Tags{}, models.Fields{}, time.Unix(0, 0)),
models.NewPoint("cpu", models.Tags{}, models.Fields{}, time.Unix(1, 0)),
models.NewPoint("cpu", models.Tags{"host": "serverA"}, models.Fields{}, time.Unix(0, 0)),
}
// Mock points writer to ensure points are passed through.
var invoked bool
e.PointsWriter.WritePointsFn = func(a []models.Point) error {
invoked = true
if !reflect.DeepEqual(points, a) {
t.Fatalf("unexpected points: %#v", a)
}
return nil
}
// Write points against two separate series.
if err := e.WritePoints(points, nil, nil); err != nil {
t.Fatal(err)
} else if !invoked {
t.Fatal("PointsWriter.WritePoints() not called")
}
}