-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from kellanburket/consumerRedesign
Consumer redesign
- Loading branch information
Showing
127 changed files
with
3,598 additions
and
8,723 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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
language: objective-c | ||
osx_image: xcode9 | ||
xcode_project: Franz.xcodeproj | ||
xcode_scheme: franz_Package | ||
|
||
branches: | ||
only: | ||
- swiftPackageManager | ||
xcode_scheme: franz-Package | ||
osx_image: xcode9 | ||
sudo: required | ||
services: | ||
- docker | ||
script: xcodebuild test -project Franz.xcodeproj -scheme Franz |
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 @@ | ||
Pods |
289 changes: 63 additions & 226 deletions
289
Example/Franz.xcodeproj/project.pbxproj → ...s Example/Franz.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// AppDelegate.swift | ||
// Franz | ||
// | ||
// Created by kellanburket on 01/24/2016. | ||
// Copyright (c) 2016 kellanburket. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
@UIApplicationMain | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
||
var window: UIWindow? | ||
|
||
} | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// ViewController.swift | ||
// Franz | ||
// | ||
// Created by kellanburket on 01/24/2016. | ||
// Copyright (c) 2016 kellanburket. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import Franz | ||
|
||
class ViewController: UIViewController { | ||
|
||
var cluster: Cluster! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
cluster = Cluster( | ||
brokers: [ | ||
("localhost", 9092) | ||
], | ||
clientId: "replica-test" | ||
) | ||
|
||
let consumer = cluster.getConsumer(topics: ["test"], groupId: "newGroup") | ||
consumer.listen { message in | ||
print(String(data: message.value, encoding: .utf8)!) | ||
} | ||
|
||
var count = 0 | ||
|
||
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { timer in | ||
self.cluster.sendMessage("test", message: "\(count)") | ||
count += 1 | ||
} | ||
} | ||
|
||
} | ||
|
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,7 @@ | ||
platform :ios, '10.0' | ||
use_frameworks! | ||
|
||
target 'Franz_Example' do | ||
pod "Franz", :path => "../" | ||
end | ||
|
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,16 @@ | ||
PODS: | ||
- Franz (0.1.0) | ||
|
||
DEPENDENCIES: | ||
- Franz (from `../`) | ||
|
||
EXTERNAL SOURCES: | ||
Franz: | ||
:path: "../" | ||
|
||
SPEC CHECKSUMS: | ||
Franz: '099af2ab9705201bc585ed3e4de8a2b703059dac' | ||
|
||
PODFILE CHECKSUM: 2cde30658617a6dbe8248094a35efba117c6dac5 | ||
|
||
COCOAPODS: 1.2.1 |
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,138 @@ | ||
// | ||
// ConsumerTests.swift | ||
// FranzTests | ||
// | ||
// Created by Luke Lau on 01/08/2017. | ||
// | ||
|
||
import XCTest | ||
import Franz | ||
|
||
class ConsumerTests: DockerTestBase { | ||
|
||
var cluster: Cluster! | ||
|
||
override func setUp() { | ||
cluster = Cluster(brokers: [("localhost", 9092)], clientId: "testClient") | ||
} | ||
|
||
func testReceive() { | ||
let helloExpectation = expectation(description: "Receives 'Hello' message"), | ||
worldExpectation = expectation(description: "Receives 'World' message"), | ||
💯Expectation = expectation(description: "Receives '💯' message") | ||
|
||
let consumer = cluster.getConsumer(topics: ["test"], groupId: "testGroup") | ||
consumer.listen { message in | ||
let string = String(data: message.value, encoding: .utf8) | ||
if string == "Hello" { | ||
helloExpectation.fulfill() | ||
} | ||
if string == "World" { | ||
worldExpectation.fulfill() | ||
} | ||
if string == "💯" { | ||
💯Expectation.fulfill() | ||
} | ||
} | ||
|
||
cluster.sendMessage("test", message: "Hello") | ||
|
||
wait(for: [helloExpectation], timeout: 10) | ||
|
||
cluster.sendMessage("test", message: "World") | ||
cluster.sendMessage("test", message: "💯") | ||
|
||
wait(for: [worldExpectation, 💯Expectation], timeout: 10) | ||
} | ||
|
||
func testCount() { | ||
let expectations = (0..<64).map { expectation(description: "Receives '\($0)'") } | ||
let consumer = cluster.getConsumer(topics: ["test"], groupId: "testGroup") | ||
consumer.listen { message in | ||
let i = Int(String(data: message.value, encoding: .utf8)!)! | ||
print("Consumed \(i)") | ||
expectations[i].fulfill() | ||
} | ||
|
||
for i in 0..<64 { | ||
Timer.scheduledTimer(withTimeInterval: TimeInterval(i) / 2, repeats: false) { _ in | ||
self.cluster.sendMessage("test", message: "\(i)") | ||
print("Produced \(i)") | ||
} | ||
} | ||
|
||
waitForExpectations(timeout: 60) | ||
} | ||
|
||
func testConsumerStops() { | ||
let consumer = cluster.getConsumer(topics: ["stop"], groupId: "newgroup") | ||
|
||
let e = expectation(description: "Receives message from start") | ||
|
||
consumer.listen { message in | ||
if String(data: message.value, encoding: .utf8)! == "test" { | ||
e.fulfill() | ||
} else { | ||
XCTFail("Shouldn't have recevied message") | ||
} | ||
} | ||
|
||
cluster.sendMessage("stop", message: "test") | ||
|
||
waitForExpectations(timeout: 10) | ||
|
||
consumer.stop() | ||
|
||
DispatchQueue.global().asyncAfter(deadline: .now() + 3) { | ||
self.cluster.sendMessage("stop", message: "stop") | ||
} | ||
|
||
Thread.sleep(forTimeInterval: 10) | ||
} | ||
|
||
func testFromStart() { | ||
cluster.sendMessage("fromStart", message: "test") | ||
|
||
let consumer1 = cluster.getConsumer(topics: ["fromStart"], groupId: "newgroup") | ||
|
||
let first = expectation(description: "Receives message from start") | ||
let second = expectation(description: "Receives second message") | ||
|
||
consumer1.listen(fromStart: true) { message in | ||
if String(data: message.value, encoding: .utf8)! == "test" { | ||
first.fulfill() | ||
} | ||
} | ||
|
||
let consumer2 = cluster.getConsumer(topics: ["fromStart"], groupId: "newGroup") | ||
|
||
consumer2.listen(fromStart: false) { message in | ||
if String(data: message.value, encoding: .utf8)! == "second" { | ||
second.fulfill() | ||
} else { | ||
XCTFail("Shouldn't have received any messages from earlier") | ||
} | ||
} | ||
|
||
wait(for: [first], timeout: 10) | ||
|
||
cluster.sendMessage("fromStart", message: "second") | ||
|
||
wait(for: [second], timeout: 10) | ||
} | ||
|
||
func testDoesntReceiveUnsubscribedTopics() { | ||
|
||
let consumer = cluster.getConsumer(topics: ["foo"], groupId: "newgroup") | ||
|
||
consumer.listen { _ in | ||
XCTFail("Shouldn't have received a message") | ||
} | ||
|
||
cluster.sendMessage("test", message: "Foo") | ||
|
||
Thread.sleep(forTimeInterval: 30) | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.