Skip to content

Commit

Permalink
Merge pull request #5 from kellanburket/consumerRedesign
Browse files Browse the repository at this point in the history
Consumer redesign
  • Loading branch information
kellanburket authored Oct 6, 2017
2 parents 725d94b + f41ccb5 commit e21ea34
Show file tree
Hide file tree
Showing 127 changed files with 3,598 additions and 8,723 deletions.
12 changes: 6 additions & 6 deletions .travis.yml
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
1 change: 1 addition & 0 deletions Cocoapods Example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pods

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -40,6 +40,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -69,6 +70,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
17 changes: 17 additions & 0 deletions Cocoapods Example/Franz/AppDelegate.swift
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.
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -29,10 +39,15 @@
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
}
File renamed without changes.
40 changes: 40 additions & 0 deletions Cocoapods Example/Franz/ViewController.swift
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
}
}

}

7 changes: 7 additions & 0 deletions Cocoapods Example/Podfile
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

16 changes: 16 additions & 0 deletions Cocoapods Example/Podfile.lock
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
138 changes: 138 additions & 0 deletions DockerTests/ConsumerTests.swift
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)
}

}

Loading

0 comments on commit e21ea34

Please sign in to comment.