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

[AMSDK-11201] - Differentiate XDM vs standard shared state via eventName #593

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions AEPCore/Sources/eventhub/EventHub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ final class EventHub {
}

sharedState.set(version: version, data: data)
self.dispatch(event: self.createSharedStateEvent(extensionName: extensionName))
self.dispatch(event: self.createSharedStateEvent(extensionName: extensionName, sharedStatetype: sharedStateType))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

Log.debug(label: self.LOG_TAG, "\(sharedStateType.rawValue.capitalized) shared state created for \(extensionName) with version \(version) and data: \n\(PrettyDictionary.prettify(data))")
}
}
Expand Down Expand Up @@ -284,7 +284,7 @@ final class EventHub {

let version = sharedState.resolve(version: 0).value == nil ? 0 : eventNumberCounter.incrementAndGet()
sharedState.set(version: version, data: data)
dispatch(event: createSharedStateEvent(extensionName: EventHubConstants.NAME))
dispatch(event: createSharedStateEvent(extensionName: EventHubConstants.NAME, sharedStatetype: .standard))
Log.debug(label: LOG_TAG, "Shared state created for \(EventHubConstants.NAME) with version \(version) and data: \n\(PrettyDictionary.prettify(data))")
}

Expand Down Expand Up @@ -328,14 +328,15 @@ final class EventHub {
guard let pendingVersion = version, let container = registeredExtensions.first(where: { $1.sharedStateName.caseInsensitiveCompare(extensionName) == .orderedSame })?.value else { return }
guard let sharedState = container.sharedState(for: sharedStateType) else { return }
sharedState.updatePending(version: pendingVersion, data: data)
dispatch(event: createSharedStateEvent(extensionName: container.sharedStateName))
dispatch(event: createSharedStateEvent(extensionName: container.sharedStateName, sharedStatetype: sharedStateType))
}

/// Creates a template `Event` for `SharedState` of the provided `extensionName`
/// - Parameter extensionName: A `String` containing the name of the extension
/// - Returns: An empty `SharedState` `Event` for the provided `extensionName`
private func createSharedStateEvent(extensionName: String) -> Event {
return Event(name: EventHubConstants.STATE_CHANGE, type: EventType.hub, source: EventSource.sharedState,
private func createSharedStateEvent(extensionName: String, sharedStatetype: SharedStateType) -> Event {
let eventName = sharedStatetype == .standard ? EventHubConstants.STATE_CHANGE : EventHubConstants.XDM_STATE_CHANGE
return Event(name: eventName, type: EventType.hub, source: EventSource.sharedState,
data: [EventHubConstants.EventDataKeys.Configuration.EVENT_STATE_OWNER: extensionName])
}

Expand Down
3 changes: 2 additions & 1 deletion AEPCore/Sources/eventhub/EventHubConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import Foundation

/// Constant values used throughout `EventHub`
enum EventHubConstants {
static let STATE_CHANGE = "STATE_CHANGE_EVENT"
static let STATE_CHANGE = "Shared state change"
static let XDM_STATE_CHANGE = "Shared state change (XDM)"
static let NAME = "com.adobe.module.eventhub"
static let FRIENDLY_NAME = "EventHub"
static let VERSION_NUMBER = "3.1.0"
Expand Down
4 changes: 2 additions & 2 deletions AEPCore/Tests/EventHubTests/EventHubTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1027,8 +1027,8 @@ class EventHubTests: XCTestCase {

let event = Event(name: "test", type: EventType.acquisition, source: EventSource.requestContent, data: nil)
eventHub.getExtensionContainer(MockExtension.self)?.registerListener(type: EventType.hub, source: EventSource.sharedState) { event in
XCTAssertEqual(event.name, EventHubConstants.STATE_CHANGE)
if event.data?[EventHubConstants.EventDataKeys.Configuration.EVENT_STATE_OWNER] as! String == EventHubTests.MOCK_EXTENSION_NAME {
XCTAssertEqual(event.name, EventHubConstants.STATE_CHANGE)
expectation.fulfill()
}
}
Expand All @@ -1052,8 +1052,8 @@ class EventHubTests: XCTestCase {

let event = Event(name: "test", type: EventType.acquisition, source: EventSource.requestContent, data: nil)
eventHub.getExtensionContainer(MockExtension.self)?.registerListener(type: EventType.hub, source: EventSource.sharedState) { event in
XCTAssertEqual(event.name, EventHubConstants.STATE_CHANGE)
if event.data?[EventHubConstants.EventDataKeys.Configuration.EVENT_STATE_OWNER] as! String == EventHubTests.MOCK_EXTENSION_NAME {
XCTAssertEqual(event.name, EventHubConstants.XDM_STATE_CHANGE)
expectation.fulfill()
}
}
Expand Down
4 changes: 2 additions & 2 deletions AEPCore/Tests/FunctionalTests/EventHubContractTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class EventHubContractTest: XCTestCase {
let sharedStateEventExpectation = XCTestExpectation(description: "Event Hub shared stated event is received")
ContractExtensionOne.eventReceivedClosure = { event in
switch event.name{
case "STATE_CHANGE_EVENT":
case "Shared state change":
sharedStateEventExpectation.fulfill()
default:
XCTAssertFalse(true)
Expand Down Expand Up @@ -156,7 +156,7 @@ class EventHubContractTest: XCTestCase {
firstEventExpectation.fulfill()
case "second":
secondEventExpectation.fulfill()
case "STATE_CHANGE_EVENT":
case "Shared state change":
sharedStateEventExpectation.fulfill()
default:
XCTAssertFalse(true)
Expand Down