Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates all gnatsd logging to use apcera/logging #4

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion conf/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func (lx *lexer) nextItem() item {
lx.state = lx.state(lx)
}
}
panic("not reached")
}

func lex(input string) *lexer {
Expand Down
54 changes: 54 additions & 0 deletions conf/lex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package conf

import (
"testing"

. "github.com/apcera/gnatsd/test/unittest"
)

// Test to make sure we get what we expect.
Expand All @@ -21,6 +23,9 @@ func expect(t *testing.T, lx *lexer, items []item) {
}

func TestSimpleKeyStringValues(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemKey, "foo", 1},
{itemString, "bar", 1},
Expand All @@ -41,6 +46,9 @@ func TestSimpleKeyStringValues(t *testing.T) {
}

func TestSimpleKeyIntegerValues(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemKey, "foo", 1},
{itemInteger, "123", 1},
Expand All @@ -55,6 +63,9 @@ func TestSimpleKeyIntegerValues(t *testing.T) {
}

func TestSimpleKeyFloatValues(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemKey, "foo", 1},
{itemFloat, "22.2", 1},
Expand All @@ -69,6 +80,9 @@ func TestSimpleKeyFloatValues(t *testing.T) {
}

func TestSimpleKeyBoolValues(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemKey, "foo", 1},
{itemBool, "true", 1},
Expand All @@ -83,6 +97,9 @@ func TestSimpleKeyBoolValues(t *testing.T) {
}

func TestComments(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemCommentStart, "", 1},
{itemText, " This is a comment", 1},
Expand All @@ -97,6 +114,9 @@ func TestComments(t *testing.T) {
}

func TestArrays(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemKey, "foo", 1},
{itemArrayStart, "", 1},
Expand Down Expand Up @@ -127,6 +147,9 @@ foo = [
`

func TestMultilineArrays(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemCommentStart, "", 2},
{itemText, " top level comment", 2},
Expand Down Expand Up @@ -160,7 +183,11 @@ foo = [
"bar"
]
`

func TestMultilineArraysNoSep(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemCommentStart, "", 2},
{itemText, " top level comment", 2},
Expand All @@ -179,6 +206,9 @@ func TestMultilineArraysNoSep(t *testing.T) {
}

func TestSimpleMap(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemKey, "foo", 1},
{itemMapStart, "", 1},
Expand All @@ -202,6 +232,9 @@ foo = {
`

func TestMultilineMap(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemKey, "foo", 2},
{itemMapStart, "", 2},
Expand All @@ -227,6 +260,9 @@ foo = {
`

func TestNestedMaps(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemKey, "foo", 2},
{itemMapStart, "", 2},
Expand All @@ -246,6 +282,9 @@ func TestNestedMaps(t *testing.T) {
}

func TestColonKeySep(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemKey, "foo", 1},
{itemInteger, "123", 1},
Expand All @@ -262,6 +301,9 @@ func TestColonKeySep(t *testing.T) {
}

func TestWhitespaceKeySep(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemKey, "foo", 1},
{itemInteger, "123", 1},
Expand All @@ -287,6 +329,9 @@ foo {
`

func TestNestedWhitespaceMaps(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemKey, "foo", 2},
{itemMapStart, "", 2},
Expand Down Expand Up @@ -315,6 +360,9 @@ map {
`

func TestOptionalSemicolons(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemKey, "foo", 2},
{itemInteger, "123", 2},
Expand All @@ -335,6 +383,9 @@ func TestOptionalSemicolons(t *testing.T) {
}

func TestSemicolonChaining(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemKey, "foo", 1},
{itemString, "1", 1},
Expand Down Expand Up @@ -365,6 +416,9 @@ fkey = five # This should be a string
`

func TestNonQuotedStrings(t *testing.T) {
StartTest(t)
defer FinishTest(t)

expectedItems := []item{
{itemKey, "foo", 2},
{itemInteger, "123", 2},
Expand Down
2 changes: 1 addition & 1 deletion conf/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func parse(data string) (p *parser, err error) {
if it.typ == itemEOF {
break
}
if err := p.processItem(it); err != nil {
if err := p.processItem(it); err != nil {
return nil, err
}
}
Expand Down
28 changes: 18 additions & 10 deletions conf/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package conf
import (
"reflect"
"testing"

. "github.com/apcera/gnatsd/test/unittest"
)

// Test to make sure we get what we expect.
Expand All @@ -22,11 +24,14 @@ func test(t *testing.T, data string, ex map[string]interface{}) {
}

func TestSimpleTopLevel(t *testing.T) {
ex := map[string]interface{} {
"foo":"1",
"bar":float64(2.2),
"baz":true,
"boo":int64(22),
StartTest(t)
defer FinishTest(t)

ex := map[string]interface{}{
"foo": "1",
"bar": float64(2.2),
"baz": true,
"boo": int64(22),
}
test(t, "foo='1'; bar=2.2; baz=true; boo=22", ex)
}
Expand All @@ -42,13 +47,16 @@ foo {
`

func TestSample1(t *testing.T) {
ex := map[string]interface{} {
"foo": map[string]interface{} {
"host": map[string]interface{} {
"ip": "127.0.0.1",
StartTest(t)
defer FinishTest(t)

ex := map[string]interface{}{
"foo": map[string]interface{}{
"host": map[string]interface{}{
"ip": "127.0.0.1",
"port": int64(4242),
},
"servers": []interface{} {"a.com", "b.com", "c.com"},
"servers": []interface{}{"a.com", "b.com", "c.com"},
},
}
test(t, sample1, ex)
Expand Down
23 changes: 18 additions & 5 deletions gnatsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ package main

import (
"flag"
"log"
"net/http"
_ "net/http/pprof"
"strings"

"github.com/apcera/gnatsd/server"
"github.com/apcera/logging"
)

func main() {
// logging setup
server.LogSetup()

opts := server.Options{}

var showVersion bool
Expand Down Expand Up @@ -73,6 +70,8 @@ func main() {
}
}

LogSetup(&opts)

// Create the server with appropriate options.
s := server.New(server.MergeOptions(fileOpts, &opts))

Expand All @@ -83,9 +82,23 @@ func main() {

// Profiler
go func() {
log.Println(http.ListenAndServe("localhost:6062", nil))
logging.Info(http.ListenAndServe("localhost:6062", nil))
}()

// Wait for clients.
s.AcceptLoop()
}

// Sets up standalone logging
func LogSetup(opts *server.Options) {
logging.ReplacePrependFunc("default",
func(l *logging.PrependLineData) string { return "" })
logging.ConfigReplaceOutput("^default$", "IWEF", "stdout://")
if opts.Debug {
logging.ConfigReplaceOutput("^default$", "@DIWEF", "stdout://")
}
if opts.Trace {
logging.ConfigReplaceOutput("^default$", "@TDIWEF", "stdout://")
}
logging.Info("Logging configured.")
}
6 changes: 3 additions & 3 deletions hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Jesteress(data []byte) uint32 {
// Cases: 0,1,2,3,4,5,6,7
if (dlen & _DWSZ) > 0 {
k1 := *(*uint64)(unsafe.Pointer(&data[i]))
h32 = uint32(uint64(h32) ^ k1) * _YP32
h32 = uint32(uint64(h32)^k1) * _YP32
i += _DWSZ
}
if (dlen & _WSZ) > 0 {
Expand Down Expand Up @@ -111,10 +111,10 @@ func Yorikke(data []byte) uint32 {
for ; dlen >= _DDDWSZ; dlen -= _DDDWSZ {
k1 := *(*uint64)(unsafe.Pointer(&data[i]))
k2 := *(*uint64)(unsafe.Pointer(&data[i+4]))
h32 = uint32((uint64(h32) ^ (((k1<<5 | k1>>27)) ^ k2)) * _YP32)
h32 = uint32((uint64(h32) ^ ((k1<<5 | k1>>27) ^ k2)) * _YP32)
k1 = *(*uint64)(unsafe.Pointer(&data[i+8]))
k2 = *(*uint64)(unsafe.Pointer(&data[i+12]))
h32b = uint32((uint64(h32b) ^ (((k1<<5 | k1>>27)) ^ k2)) * _YP32)
h32b = uint32((uint64(h32b) ^ ((k1<<5 | k1>>27) ^ k2)) * _YP32)
i += _DDDWSZ
}
if (dlen & _DDWSZ) > 0 {
Expand Down