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

Initial support for testing #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<properties>
<dropwizard.version>0.9.1</dropwizard.version>
<jetty.version>9.2.13.v20150730</jetty.version>
<junit.version>4.12</junit.version>
</properties>

<dependencies>
Expand All @@ -30,6 +31,18 @@
<artifactId>jetty-proxy</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>1.58</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not put this version number with the others in properties?

Copy link
Author

Choose a reason for hiding this comment

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

no reason, I'll fix that.

Copy link
Member

Choose a reason for hiding this comment

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

I go back and forth. If it’s version used by a number of jar files that are related, then I like using the interpolation. If it’s a single jar, then it’s yet another level of indirection.

Regardless, good to see…

On May 18, 2016, at 10:59 AM, Matt Overstreet [email protected] wrote:

In pom.xml #9 (comment):

@@ -30,6 +31,18 @@
jetty-proxy
${jetty.version}

  •  <groupId>junit</groupId>
    
  •  <artifactId>junit</artifactId>
    
  •  <scope>test</scope>
    
  •  <version>${junit.version}</version>
    
  •  <groupId>com.github.tomakehurst</groupId>
    
  •  <artifactId>wiremock</artifactId>
    
  •  <version>1.58</version>
    
    no reason, I'll fix that.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub https://github.com/o19s/grand_central/pull/9/files/36fa649c8da1d0d74db04350b6894abcc4028e73#r63719588


Eric Pugh | Principal | OpenSource Connections, LLC | 434.466.1467 | http://www.opensourceconnections.com http://www.opensourceconnections.com/ | My Free/Busy http://tinyurl.com/eric-cal
Co-Author: Apache Solr Enterprise Search Server, 3rd Ed https://www.packtpub.com/big-data-and-business-intelligence/apache-solr-enterprise-search-server-third-edition-raw
This e-mail and all contents, including attachments, is considered to be Company Confidential unless explicitly stated otherwise, regardless of whether attachments are marked as such.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see your point on level of indirection, but it is convenient to have all version numbers together. If we include them with each dependency then you're crawling through each dependency's XML block a) looking for the right block and b) looking for the version element.

Fortunately our number of dependencies is small so it isn't that big of a task. I'm open for either approach. @epugh has a point.

</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.jackson.JsonSnakeCase;
import io.dropwizard.setup.Environment;
import org.apache.http.client.HttpClient;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.NotNull;
Expand All @@ -27,6 +25,9 @@ public class KubernetesConfiguration {
@NotEmpty
private String namespace;

// this can be null
private String protocol;

@JsonProperty
public String getMasterIp() {
return masterIp;
Expand All @@ -42,6 +43,16 @@ public String getUsername() {
return username;
}

@JsonProperty
public String getProtocol() {
return (protocol == null) ? "https" : protocol;
}

@JsonProperty
public void setProtocol(String protocol) {
this.protocol = protocol;
}

@JsonProperty
public void setUsername(String username) {
this.username = username;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class PodManager {
* @param keystorePath Path to the Java Keystore containing trusted certificates
* @param maximumPodCount Maximum number of pods to ever have running at once
* @param refreshIntervalInMs Interval with which to refresh the pods
* @param podYamlPath the location of the yaml config for the application pod
*/
public PodManager(KubernetesConfiguration k8sConfiguration,
String keystorePath,
Expand Down Expand Up @@ -343,7 +344,7 @@ else if (left.getLastRequest() < right.getLastRequest())
* @throws IOException
*/
private void refreshPods() throws IOException {
HttpGet podsGet = new HttpGet("https://" + k8sConfiguration.getMasterIp() + ":443/api/v1/namespaces/" + k8sConfiguration.getNamespace() + "/pods");
HttpGet podsGet = new HttpGet(k8sConfiguration.getProtocol() + "://" + k8sConfiguration.getMasterIp() + "/api/v1/namespaces/" + k8sConfiguration.getNamespace() + "/pods");
Copy link
Contributor

Choose a reason for hiding this comment

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

We could drop the protocol and master ip and just have a URL.

master_url: https://k8s.example.com
# or
master_url: http://k8s.example.com

I'm fairly certain I just went with master IP since that is what the GKE console displayed. It's fairly straightforward to reason out.

Copy link
Author

Choose a reason for hiding this comment

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

I like having an optional protocol for that reason. It's less to think about when you are configuring it. In almost all cases (except test) we can assume it's https.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to see the GKE dashboard again and verify they just surface up an IP.

If we rename the parameter to master_url and include https in the sample config file we have the same number of parameters today and don't rely on a hidden configuration value.


try (CloseableHttpResponse response = httpClient.execute(podsGet, httpContext)) {
HttpEntity entity = response.getEntity();
Expand Down
77 changes: 77 additions & 0 deletions src/test/com/o19s/grandcentral/kubernetes/PodManagerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.o19s.grandcentral.kubernetes;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import static com.github.tomakehurst.wiremock.client.WireMock.*;

;
/**
* Created by Omnifroodle on 5/17/16.
*/
public class PodManagerTest {
private KubernetesConfiguration kubecfg;
@Rule
public WireMockRule wireMockRule = new WireMockRule(8888);

@Before
public void setUp() throws Exception {
this.kubecfg = new KubernetesConfiguration();
kubecfg.setMasterIp("127.0.0.1:8888");
kubecfg.setProtocol("http");
kubecfg.setNamespace("test");
kubecfg.setUsername("fred");
kubecfg.setPassword("flintstone");
}

@After
public void tearDown() throws Exception {
}

@Test
public void testGet() throws Exception {

}

@Test
public void testContains() throws Exception {

}

@Test
public void testAdd() throws Exception {

}

@Test
public void testRefreshPods() throws Exception {
stubFor(get(urlEqualTo("/api/v1/namespaces/test/pods"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/json")
.withBody("{\"items\":[" +
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to have this stored in a JSON file on disk then consumed by the test?

Copy link
Author

Choose a reason for hiding this comment

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

I think yes, I was actually looking into that last night. I'm trying to decide which is more readable, ugly multiline java string literals or a set of hidden away response files

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see it as being hidden away the full path will be here in the test. I believe that's a fairly common pattern to keep tests readable / concise. It is slightly inconvenient to track down the file when it needs to be changed, but I prefer the cleaner test.

" {" +
" \"metadata\":{" +
" \"name\": \"abc\"" +
" }," +
" \"status\": {" +
" \"phase\": \"Running\"," +
" \"podIP\": \"1.1.1.1\"" +
" }" +
" }," +
" {" +
" \"metadata\":{" +
" \"name\": \"abcd\"" +
" }," +
" \"status\": {" +
" \"phase\": \"Running\"," +
" \"podIP\": \"1.1.1.2\"" +
" }" +
" }" +
" ]}")));

PodManager manager = new PodManager(this.kubecfg, "config/grandcentral.jks", 100, 1, "./config/configuration.yml");
}
}