Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.github.dockerjava.api.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.EqualsAndHashCode;
import lombok.ToString;

Expand All @@ -11,6 +14,7 @@
/**
* @author Vangie Du (duwan@live.com)
*/
@JsonPropertyOrder({"Name", "Soft", "Hard"})
@EqualsAndHashCode
@ToString
public class Ulimit implements Serializable {
Expand All @@ -19,16 +23,20 @@ public class Ulimit implements Serializable {
@JsonProperty("Name")
private String name;

@JsonProperty("Soft")
private Integer soft;
private Long soft;

@JsonProperty("Hard")
private Integer hard;
private Long hard;

public Ulimit() {
}

@Deprecated
public Ulimit(String name, int soft, int hard) {
this(name, (long) soft, (long) hard);
}

@JsonCreator
public Ulimit(@JsonProperty("Name") String name, @JsonProperty("Soft") long soft, @JsonProperty("Hard") long hard) {
requireNonNull(name, "Name is null");
this.name = name;
this.soft = soft;
Expand All @@ -39,11 +47,25 @@ public String getName() {
return name;
}

@Deprecated
@JsonIgnore
public Integer getSoft() {
return soft;
return soft != null ? soft.intValue() : null;
}

@Deprecated
@JsonIgnore
public Integer getHard() {
return hard != null ? hard.intValue() : null;
}

@JsonProperty("Soft")
public Long getSoftLong() {
return soft;
}

@JsonProperty("Hard")
public Long getHardLong() {
return hard;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.dockerjava.api.model;

import com.github.dockerjava.test.serdes.JSONTestHelper;
import org.junit.Test;

import static org.hamcrest.Matchers.arrayContaining;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;

public class UlimitsTest {

@Test
public void usesToJson() throws Exception {
Ulimit[] ulimits = new Ulimit[]{
new Ulimit("nproc", 709, 1026),
new Ulimit("nofile", 1024, 4096),
new Ulimit("core", 99999999998L, 99999999999L)
};
String json = JSONTestHelper.getMapper().writeValueAsString(ulimits);

assertThat(json, is("[{\"Name\":\"nproc\",\"Soft\":709,\"Hard\":1026},{\"Name\":\"nofile\",\"Soft\":1024,\"Hard\":4096},{\"Name\":\"core\",\"Soft\":99999999998,\"Hard\":99999999999}]"));
}

@Test
public void usesFromJson() throws Exception {
Ulimit[] ulimits = JSONTestHelper.getMapper().readValue("[{\"Name\":\"nproc\",\"Soft\":709,\"Hard\":1026},{\"Name\":\"nofile\",\"Soft\":1024,\"Hard\":4096},{\"Name\":\"core\",\"Soft\":99999999998,\"Hard\":99999999999}]", Ulimit[].class);

assertThat(ulimits, notNullValue());
assertThat(ulimits, arrayContaining(
new Ulimit("nproc", 709, 1026),
new Ulimit("nofile", 1024, 4096),
new Ulimit("core", 99999999998L, 99999999999L)
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,28 @@ public void createContainerWithULimits() throws DockerException {

}

@Test
public void createContainerWithIntegerBoundsExceedingULimit() throws DockerException {
String containerName = "containercoreulimit" + dockerRule.getKind();
Ulimit[] ulimits = {new Ulimit("core", 99999999998L, 99999999999L)};

CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
.withName(containerName)
.withHostConfig(newHostConfig()
.withUlimits(ulimits))
.exec();

LOG.info("Created container {}", container.toString());

assertThat(container.getId(), not(isEmptyString()));

InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

assertThat(Arrays.asList(inspectContainerResponse.getHostConfig().getUlimits()),
contains(new Ulimit("core", 99999999998L, 99999999999L)));

}

@Test
public void createContainerWithLabels() throws DockerException {

Expand Down