-
Notifications
You must be signed in to change notification settings - Fork 54
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
Stop Stream Creation for existing topics if configs don't match #52
Merged
Merged
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8df66ef
Merge pull request #1 from homeaway/master
arunvasudevan 449ad5f
Removing update topics functionality in Stream Registry
arunvasudevan 78bf0ea
Changelog
arunvasudevan 6b0b196
Merge branch 'master' into master
neoword 0bed4e4
Stop Stream Creation for existing topics if configs don't match
arunvasudevan 44a59eb
Updating Changelog
arunvasudevan 8934a12
Merge branch 'master' into master
neoword 66e5457
Merge branch 'master' into master
neoword 4113a0b
Updating CHANGELOG to 0.4.1
neoword f3ecea9
Checkpoint. WIP! DO NOT MERGE
neoword da75b20
CHECKPOINT. IT Tests failing
neoword 7ffa595
Tests passing
neoword ae88d04
Adding more tests to be comprehensive
neoword f0da488
Updating comments
neoword a8b2a44
Merge pull request #2 from homeaway/arun-master
arunvasudevan 59a6d4e
Updating changelog to version 0.4.2
arunvasudevan ad8b9c0
Merge branch 'master' into master
neoword 3fbfd33
Merge branch 'master' into master
neoword File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
123 changes: 123 additions & 0 deletions
123
core/src/test/java/com/homeaway/streamingplatform/db/dao/impl/KafkaManagerImplTest.java
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,123 @@ | ||
/* Copyright (c) 2018 Expedia Group. | ||
* All rights reserved. http://www.homeaway.com | ||
|
||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
|
||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.homeaway.streamingplatform.db.dao.impl; | ||
|
||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.when; | ||
import static org.powermock.api.mockito.PowerMockito.mockStatic; | ||
import static org.powermock.api.mockito.PowerMockito.spy; | ||
import static org.powermock.api.mockito.PowerMockito.whenNew; | ||
|
||
import java.util.Collections; | ||
import java.util.Properties; | ||
|
||
import kafka.admin.AdminUtils; | ||
import kafka.server.ConfigType; | ||
import kafka.utils.ZkUtils; | ||
|
||
import org.I0Itec.zkclient.ZkClient; | ||
import org.I0Itec.zkclient.ZkConnection; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.MockitoJUnit; | ||
import org.mockito.junit.MockitoRule; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
|
||
import com.homeaway.streamingplatform.configuration.KafkaProducerConfig; | ||
import com.homeaway.streamingplatform.exceptions.StreamCreationException; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest({KafkaManagerImpl.class, AdminUtils.class}) | ||
public class KafkaManagerImplTest { | ||
|
||
private static final String topic = "kafka-manager-test"; | ||
private static final int partitions = 2; | ||
private static final int replicationFactor = 3; | ||
private static Properties props = new Properties(); | ||
|
||
@Mock private ZkUtils zkUtils; | ||
@Mock private ZkClient zkClient; | ||
@Mock private ZkConnection zkConnection; | ||
|
||
@InjectMocks | ||
private KafkaManagerImpl kafkaManager; | ||
|
||
@Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); | ||
|
||
@Before | ||
public void setup() throws Exception{ | ||
props.put("key1", "val1"); | ||
props.put("key2", 2); | ||
props.put(KafkaProducerConfig.ZOOKEEPER_QUORUM, ""); | ||
|
||
kafkaManager = new KafkaManagerImpl(); | ||
|
||
mockStatic(AdminUtils.class); | ||
|
||
whenNew(ZkClient.class).withAnyArguments().thenReturn(zkClient); | ||
whenNew(ZkConnection.class).withArguments(Mockito.anyString()).thenReturn(zkConnection); | ||
whenNew(ZkUtils.class).withAnyArguments().thenReturn(zkUtils); | ||
|
||
when(AdminUtils.fetchEntityConfig(zkUtils, ConfigType.Topic(), topic)).thenReturn(props); | ||
} | ||
|
||
@Test(expected = StreamCreationException.class) | ||
public void testUpsertTopicsForNewStream(){ | ||
// Mock it as an existing topic | ||
when(AdminUtils.topicExists(zkUtils, topic)).thenReturn(true); | ||
|
||
//New Stream | ||
kafkaManager.upsertTopics(Collections.singleton(topic), partitions, replicationFactor, props, true); | ||
} | ||
|
||
@Test | ||
public void testUpsertTopicsForExistingStream() { | ||
// Mock it as an existing topic | ||
when(AdminUtils.topicExists(zkUtils, topic)).thenReturn(true); | ||
|
||
KafkaManagerImpl kafkaManagerSpy = spy(kafkaManager); | ||
doNothing().doThrow(new RuntimeException()).when(kafkaManagerSpy).createTopics(Mockito.anyCollection(), Mockito.anyInt(), Mockito.anyInt(), Mockito.any(), Mockito.anyMap()); | ||
|
||
//Existing Stream | ||
kafkaManagerSpy.upsertTopics(Collections.singleton(topic), partitions, replicationFactor, props, false); | ||
|
||
//Assert if 0 topic is added to the list to be created | ||
Assert.assertEquals(0,kafkaManagerSpy.topicsToCreate.size()); | ||
} | ||
|
||
|
||
@Test | ||
public void testUpsertTopicsForNewTopic() { | ||
// Mock it as a new topic | ||
when(AdminUtils.topicExists(zkUtils, topic)).thenReturn(false); | ||
|
||
KafkaManagerImpl kafkaManagerSpy = spy(kafkaManager); | ||
doNothing().doThrow(new RuntimeException()).when(kafkaManagerSpy).createTopics(Mockito.anyCollection(), Mockito.anyInt(), Mockito.anyInt(), Mockito.any(), Mockito.anyMap()); | ||
|
||
//Existing Stream | ||
kafkaManagerSpy.upsertTopics(Collections.singleton(topic), partitions, replicationFactor, props, false); | ||
|
||
//Assert if 1 topic is added to the list to be created | ||
Assert.assertEquals(1, kafkaManagerSpy.topicsToCreate.size()); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is being targetted for 0.4.2