Skip to content
This repository was archived by the owner on Oct 18, 2022. It is now read-only.

Commit 02d0996

Browse files
committed
Initial commit
0 parents  commit 02d0996

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2661
-0
lines changed

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Xcode
2+
#
3+
build/
4+
*.pbxuser
5+
!default.pbxuser
6+
*.mode1v3
7+
!default.mode1v3
8+
*.mode2v3
9+
!default.mode2v3
10+
*.perspectivev3
11+
!default.perspectivev3
12+
xcuserdata
13+
*.xccheckout
14+
*.moved-aside
15+
DerivedData
16+
*.hmap
17+
*.ipa
18+
*.xcuserstate
19+
20+
# CocoaPods
21+
#
22+
Pods/

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "Example/Vendor/Nimble"]
2+
path = Example/Vendor/Nimble
3+
url = [email protected]:Quick/Nimble.git
4+
[submodule "Example/Vendor/Quick"]
5+
path = Example/Vendor/Quick
6+
url = [email protected]:Quick/Quick.git

Example/Podfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source 'https://github.com/CocoaPods/Specs'
2+
3+
target 'Puree', :exclusive => true do
4+
pod "Puree", :path => "../"
5+
end

Example/Podfile.lock

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
PODS:
2+
- CocoaLumberjack (1.9.2):
3+
- CocoaLumberjack/Extensions (= 1.9.2)
4+
- CocoaLumberjack/Core (1.9.2)
5+
- CocoaLumberjack/Extensions (1.9.2):
6+
- CocoaLumberjack/Core
7+
- Puree (1.0.0):
8+
- YapDatabase (~> 2.5.4)
9+
- YapDatabase (2.5.4):
10+
- YapDatabase/standard (= 2.5.4)
11+
- YapDatabase/common (2.5.4):
12+
- CocoaLumberjack (~> 1)
13+
- YapDatabase/standard (2.5.4):
14+
- YapDatabase/common
15+
16+
DEPENDENCIES:
17+
- Puree (from `../`)
18+
19+
EXTERNAL SOURCES:
20+
Puree:
21+
:path: ../
22+
23+
SPEC CHECKSUMS:
24+
CocoaLumberjack: 205769c032b5fef85b92472046bcc8b7e7c8a817
25+
Puree: e4f2adb9fed2f87b4d1cab4dccc9d68c7cc2b049
26+
YapDatabase: c1d6912df1b4a160f7373ee7657d360e29bb00fd
27+
28+
COCOAPODS: 0.35.0

Example/Puree.xcodeproj/project.pbxproj

Lines changed: 575 additions & 0 deletions
Large diffs are not rendered by default.

Example/Puree.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0600"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "NO"
13+
buildForArchiving = "NO"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "6003F5AD195388D20070C39A"
18+
BuildableName = "Puree.xctest"
19+
BlueprintName = "Puree"
20+
ReferencedContainer = "container:Puree.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
27+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
28+
shouldUseLaunchSchemeArgsEnv = "YES"
29+
buildConfiguration = "Debug">
30+
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "6003F5AD195388D20070C39A"
36+
BuildableName = "Puree.xctest"
37+
BlueprintName = "Puree"
38+
ReferencedContainer = "container:Puree.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
41+
</Testables>
42+
<MacroExpansion>
43+
<BuildableReference
44+
BuildableIdentifier = "primary"
45+
BlueprintIdentifier = "6003F5AD195388D20070C39A"
46+
BuildableName = "Puree.xctest"
47+
BlueprintName = "Puree"
48+
ReferencedContainer = "container:Puree.xcodeproj">
49+
</BuildableReference>
50+
</MacroExpansion>
51+
</TestAction>
52+
<LaunchAction
53+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
54+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
55+
launchStyle = "0"
56+
useCustomWorkingDirectory = "NO"
57+
buildConfiguration = "Debug"
58+
ignoresPersistentStateOnLaunch = "NO"
59+
debugDocumentVersioning = "YES"
60+
allowLocationSimulation = "YES">
61+
<MacroExpansion>
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "6003F5AD195388D20070C39A"
65+
BuildableName = "Puree.xctest"
66+
BlueprintName = "Puree"
67+
ReferencedContainer = "container:Puree.xcodeproj">
68+
</BuildableReference>
69+
</MacroExpansion>
70+
<AdditionalOptions>
71+
</AdditionalOptions>
72+
</LaunchAction>
73+
<ProfileAction
74+
shouldUseLaunchSchemeArgsEnv = "YES"
75+
savedToolIdentifier = ""
76+
useCustomWorkingDirectory = "NO"
77+
buildConfiguration = "Release"
78+
debugDocumentVersioning = "YES">
79+
<MacroExpansion>
80+
<BuildableReference
81+
BuildableIdentifier = "primary"
82+
BlueprintIdentifier = "6003F5AD195388D20070C39A"
83+
BuildableName = "Puree.xctest"
84+
BlueprintName = "Puree"
85+
ReferencedContainer = "container:Puree.xcodeproj">
86+
</BuildableReference>
87+
</MacroExpansion>
88+
</ProfileAction>
89+
<AnalyzeAction
90+
buildConfiguration = "Debug">
91+
</AnalyzeAction>
92+
<ArchiveAction
93+
buildConfiguration = "Release"
94+
revealArchiveInOrganizer = "YES">
95+
</ArchiveAction>
96+
</Scheme>

Example/Puree.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Tests/PURLogStoreSpec.swift

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
import Quick
2+
import Nimble
3+
4+
class PURLogStoreSpec: QuickSpec {
5+
override func spec() {
6+
describe("readwrite logs", {
7+
let date = NSDate().timeIntervalSince1970
8+
let logStoreDBPath = NSTemporaryDirectory().stringByAppendingPathComponent("LogStoreSpec_\(date).db")
9+
var logStore : PURLogStore!
10+
11+
class TestOutputA : PUROutput {
12+
13+
}
14+
15+
class TestOutputB : PUROutput {
16+
17+
}
18+
19+
beforeSuite({
20+
logStore = PURLogStore(databasePath: logStoreDBPath)
21+
logStore.prepare()
22+
})
23+
24+
beforeEach({
25+
logStore.clearAll()
26+
})
27+
28+
it("should write log", {
29+
let outputA = TestOutputA(logger: nil, tagPattern: "test.*")
30+
let outputB = TestOutputB(logger: nil, tagPattern: "test.*")
31+
32+
var count = -1
33+
logStore.retrieveLogsForPattern("test.*", output:outputA, completion: { logs in
34+
if logs != nil {
35+
count = logs.count
36+
}
37+
})
38+
expect(count).toEventually(equal(0), timeout: 1)
39+
40+
logStore.addLog(PURLog(tag: "test.apple", date: NSDate(), userInfo: nil), fromOutput: outputA)
41+
logStore.addLog(PURLog(tag: "test.apple", date: NSDate(), userInfo: nil), fromOutput: outputA)
42+
logStore.addLog(PURLog(tag: "test.banana", date: NSDate(), userInfo: nil), fromOutput: outputA)
43+
logStore.addLog(PURLog(tag: "test.banana", date: NSDate(), userInfo: nil), fromOutput: outputA)
44+
logStore.addLog(PURLog(tag: "test.apple", date: NSDate(), userInfo: nil), fromOutput: outputB)
45+
46+
logStore.retrieveLogsForPattern("test.*", output:outputA, completion: { logs in
47+
if logs != nil {
48+
count = logs.count
49+
}
50+
})
51+
expect(count).toEventually(equal(4), timeout: 1)
52+
})
53+
54+
it("should write logs all together", {
55+
let outputA = TestOutputA(logger: nil, tagPattern: "test.*")
56+
let outputB = TestOutputB(logger: nil, tagPattern: "test.*")
57+
58+
var count = -1
59+
logStore.retrieveLogsForPattern("test.*", output: outputA, completion: { logs in
60+
if logs != nil {
61+
count = logs.count
62+
}
63+
})
64+
expect(count).toEventually(equal(0), timeout: 1)
65+
66+
logStore.addLogs([
67+
PURLog(tag: "test.apple", date: NSDate(), userInfo: nil),
68+
PURLog(tag: "test.apple", date: NSDate(), userInfo: nil),
69+
PURLog(tag: "test.apple", date: NSDate(), userInfo: nil),
70+
PURLog(tag: "test.banana", date: NSDate(), userInfo: nil),
71+
PURLog(tag: "test.banana", date: NSDate(), userInfo: nil),
72+
], fromOutput:outputA);
73+
74+
logStore.addLogs([
75+
PURLog(tag: "test.apple", date: NSDate(), userInfo: nil),
76+
PURLog(tag: "test.banana", date: NSDate(), userInfo: nil),
77+
], fromOutput:outputB);
78+
79+
logStore.retrieveLogsForPattern("test.*", output: outputA, completion: { logs in
80+
if logs != nil {
81+
count = logs.count
82+
}
83+
})
84+
expect(count).toEventually(equal(5), timeout: 1)
85+
})
86+
87+
it("should remove logs", {
88+
let outputA = TestOutputA(logger: nil, tagPattern: "test.*")
89+
let outputB = TestOutputB(logger: nil, tagPattern: "test.*")
90+
91+
let firstChunk = [
92+
PURLog(tag: "test.apple", date: NSDate(), userInfo: nil),
93+
PURLog(tag: "test.banana", date: NSDate(), userInfo: nil),
94+
]
95+
96+
logStore.addLogs(firstChunk + [
97+
PURLog(tag: "test.apple", date: NSDate(), userInfo: nil),
98+
PURLog(tag: "test.apple", date: NSDate(), userInfo: nil),
99+
PURLog(tag: "test.banana", date: NSDate(), userInfo: nil),
100+
], fromOutput:outputA);
101+
102+
logStore.addLogs([
103+
PURLog(tag: "test.apple", date: NSDate(), userInfo: nil),
104+
PURLog(tag: "test.banana", date: NSDate(), userInfo: nil),
105+
], fromOutput:outputB);
106+
107+
var count = -1
108+
logStore.retrieveLogsForPattern("test.*", output: outputA, completion: { logs in
109+
if logs != nil {
110+
count = logs.count
111+
}
112+
})
113+
expect(count).toEventually(equal(5), timeout: 1)
114+
115+
logStore.retrieveLogsForPattern("test.*", output: outputB, completion: { logs in
116+
if logs != nil {
117+
count = logs.count
118+
}
119+
})
120+
expect(count).toEventually(equal(2), timeout: 1)
121+
122+
logStore.removeLogs(firstChunk, fromOutput: outputA)
123+
124+
logStore.retrieveLogsForPattern("test.*", output: outputA, completion: { logs in
125+
if logs != nil {
126+
count = logs.count
127+
}
128+
})
129+
expect(count).toEventually(equal(3), timeout: 1)
130+
131+
logStore.retrieveLogsForPattern("test.*", output: outputB, completion: { logs in
132+
if logs != nil {
133+
count = logs.count
134+
}
135+
})
136+
expect(count).toEventually(equal(2), timeout: 1)
137+
})
138+
})
139+
140+
describe("stress test", {
141+
let date = NSDate().timeIntervalSince1970
142+
let logStoreDBPath = NSTemporaryDirectory().stringByAppendingPathComponent("LogStoreSpec_\(date).db")
143+
var logStore : PURLogStore!
144+
145+
let outputA = PUROutput(logger: nil, tagPattern: "testA.*")
146+
let outputB = PUROutput(logger: nil, tagPattern: "testB.*")
147+
let outputC = PUROutput(logger: nil, tagPattern: "testC.*")
148+
149+
beforeSuite({
150+
logStore = PURLogStore(databasePath: logStoreDBPath)
151+
logStore.prepare()
152+
})
153+
154+
it("write (3 + 3 + 4) * 100 logs (1000 logs)", {
155+
for i in 1...100 {
156+
logStore.addLogs([
157+
PURLog(tag: "testA.apple", date: NSDate(), userInfo: nil),
158+
PURLog(tag: "testA.banana", date: NSDate(), userInfo: nil),
159+
PURLog(tag: "testA.mango", date: NSDate(), userInfo: nil),
160+
], fromOutput:outputA);
161+
162+
logStore.addLogs([
163+
PURLog(tag: "testB.apple", date: NSDate(), userInfo: nil),
164+
PURLog(tag: "testB.banana", date: NSDate(), userInfo: nil),
165+
PURLog(tag: "testB.mango", date: NSDate(), userInfo: nil),
166+
], fromOutput:outputB);
167+
168+
logStore.addLogs([
169+
PURLog(tag: "testC.apple", date: NSDate(), userInfo: nil),
170+
PURLog(tag: "testC.banana", date: NSDate(), userInfo: nil),
171+
PURLog(tag: "testC.mango", date: NSDate(), userInfo: nil),
172+
PURLog(tag: "testC.peach", date: NSDate(), userInfo: nil),
173+
], fromOutput:outputC);
174+
}
175+
})
176+
177+
it("write 1 * 1000 logs (1000 logs)", {
178+
for i in 1...1000 {
179+
logStore.addLog(PURLog(tag: "testC.peach", date: NSDate(), userInfo: nil), fromOutput:outputC);
180+
}
181+
})
182+
183+
it("read testA.* logs", {
184+
var count = -1
185+
logStore.retrieveLogsForPattern("testA.*", output: outputA, completion: { logs in
186+
if logs != nil {
187+
count = logs.count
188+
}
189+
})
190+
expect(count).toEventually(equal(300), timeout: 3)
191+
})
192+
})
193+
}
194+
}

0 commit comments

Comments
 (0)