-
Notifications
You must be signed in to change notification settings - Fork 53
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
Luke Kim
committed
Jan 25, 2016
1 parent
736bacd
commit 041faba
Showing
14 changed files
with
335 additions
and
84 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 |
---|---|---|
|
@@ -22,3 +22,6 @@ _testmain.go | |
*.exe | ||
*.test | ||
*.prof | ||
|
||
# OS specific | ||
.DS_Store |
File renamed without changes.
File renamed without changes.
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
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
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,10 @@ | ||
package appinsights | ||
|
||
import "testing" | ||
|
||
func TestClientBurstPerformance(t *testing.T) { | ||
telemetryClient := NewTelemetryClient("") | ||
for i := 0; i < 1000000; i++ { | ||
telemetryClient.TrackTrace("A message") | ||
} | ||
} |
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
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,55 @@ | ||
package appinsights | ||
|
||
type DiagnosticsMessageWriter interface { | ||
Write(string) | ||
appendListener(*diagnosticsMessageListener) | ||
} | ||
|
||
type diagnosticsMessageWriter struct { | ||
listeners []chan string | ||
} | ||
|
||
type DiagnosticsMessageProcessor func(string) | ||
|
||
type DiagnosticsMessageListener interface { | ||
ProcessMessages(DiagnosticsMessageProcessor) | ||
} | ||
|
||
type diagnosticsMessageListener struct { | ||
channel chan string | ||
} | ||
|
||
var writer *diagnosticsMessageWriter = &diagnosticsMessageWriter{ | ||
listeners: make([]chan string, 0), | ||
} | ||
|
||
func getDiagnosticsMessageWriter() DiagnosticsMessageWriter { | ||
return writer | ||
} | ||
|
||
func NewDiagnosticsMessageListener() DiagnosticsMessageListener { | ||
listener := &diagnosticsMessageListener { | ||
channel: make(chan string), | ||
} | ||
|
||
writer.appendListener(listener) | ||
|
||
return listener | ||
} | ||
|
||
func (writer *diagnosticsMessageWriter) appendListener(listener *diagnosticsMessageListener) { | ||
writer.listeners = append(writer.listeners, listener.channel) | ||
} | ||
|
||
func (writer *diagnosticsMessageWriter) Write(message string) { | ||
for _, c := range writer.listeners { | ||
c <- message | ||
} | ||
} | ||
|
||
func (listener *diagnosticsMessageListener) ProcessMessages(process DiagnosticsMessageProcessor) { | ||
for { | ||
message := <- listener.channel | ||
process(message) | ||
} | ||
} |
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,42 @@ | ||
package appinsights | ||
|
||
import "testing" | ||
import "sync" | ||
|
||
func TestDiagnosticsWriterIsSingleton(t *testing.T) { | ||
diagWriter1 := getDiagnosticsMessageWriter() | ||
diagWriter2 := getDiagnosticsMessageWriter() | ||
|
||
if diagWriter1 != diagWriter2 { | ||
t.Errorf("getDiagnosticsMessageWriter() returned difference instances.") | ||
} | ||
} | ||
|
||
func TestMessageSentToConsumers(t *testing.T) { | ||
diagWriter := getDiagnosticsMessageWriter() | ||
|
||
original := "test" | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(2) | ||
|
||
listener1 := NewDiagnosticsMessageListener() | ||
go listener1.ProcessMessages(func(message string) { | ||
if message != original { | ||
t.Errorf("listener1 returned difference messages, want '%s' got '%s'.", original, message) | ||
} | ||
wg.Done() | ||
}) | ||
|
||
listener2 := NewDiagnosticsMessageListener() | ||
go listener2.ProcessMessages(func(message string) { | ||
if message != original { | ||
t.Errorf("listener2 returned difference messages, want '%s' got '%s'.", original, message) | ||
} | ||
wg.Done() | ||
}) | ||
|
||
diagWriter.Write(original) | ||
|
||
wg.Wait() | ||
} |
Oops, something went wrong.