4
4
import com .github .dockerjava .api .model .ContainerSpec ;
5
5
import com .github .dockerjava .api .model .EndpointResolutionMode ;
6
6
import com .github .dockerjava .api .model .EndpointSpec ;
7
+ import com .github .dockerjava .api .model .Mount ;
8
+ import com .github .dockerjava .api .model .MountType ;
7
9
import com .github .dockerjava .api .model .Network ;
8
10
import com .github .dockerjava .api .model .NetworkAttachmentConfig ;
9
11
import com .github .dockerjava .api .model .PortConfig ;
14
16
import com .github .dockerjava .api .model .ServiceSpec ;
15
17
import com .github .dockerjava .api .model .SwarmSpec ;
16
18
import com .github .dockerjava .api .model .TaskSpec ;
19
+ import com .github .dockerjava .api .model .TmpfsOptions ;
17
20
import com .google .common .collect .ImmutableMap ;
18
21
import com .google .common .collect .Lists ;
19
22
import org .junit .Test ;
20
23
import org .slf4j .Logger ;
21
24
import org .slf4j .LoggerFactory ;
22
25
26
+ import java .util .Collections ;
23
27
import java .util .List ;
24
28
25
29
import static com .github .dockerjava .junit .DockerRule .DEFAULT_IMAGE ;
@@ -44,7 +48,7 @@ public void testCreateService() throws DockerException {
44
48
.withTaskTemplate (new TaskSpec ()
45
49
.withContainerSpec (new ContainerSpec ()
46
50
.withImage (DEFAULT_IMAGE ))))
47
- .exec ();
51
+ .exec ();
48
52
49
53
List <Service > services = dockerRule .getClient ().listServicesCmd ()
50
54
.withNameFilter (Lists .newArrayList (SERVICE_NAME ))
@@ -79,7 +83,7 @@ public void testCreateServiceWithNetworks() {
79
83
.withTarget (networkId )
80
84
.withAliases (Lists .<String >newArrayList ("alias1" , "alias2" ))
81
85
))
82
- .withLabels (ImmutableMap .of ("com.docker.java.usage" ,"SwarmServiceIT" ))
86
+ .withLabels (ImmutableMap .of ("com.docker.java.usage" , "SwarmServiceIT" ))
83
87
.withMode (new ServiceModeConfig ().withReplicated (
84
88
new ServiceReplicatedModeOptions ()
85
89
.withReplicas (1 )
@@ -104,4 +108,29 @@ public void testCreateServiceWithNetworks() {
104
108
dockerRule .getClient ().removeServiceCmd (SERVICE_NAME ).exec ();
105
109
}
106
110
111
+ @ Test
112
+ public void testCreateServiceWithTmpfs () {
113
+ dockerRule .getClient ().initializeSwarmCmd (new SwarmSpec ())
114
+ .withListenAddr ("127.0.0.1" )
115
+ .withAdvertiseAddr ("127.0.0.1" )
116
+ .exec ();
117
+ Mount tmpMount = new Mount ().withTmpfsOptions (new TmpfsOptions ().withSizeBytes (600L )).withTarget ("/tmp/foo" );
118
+
119
+ dockerRule .getClient ().createServiceCmd (new ServiceSpec ()
120
+ .withName (SERVICE_NAME )
121
+ .withTaskTemplate (new TaskSpec ()
122
+ .withContainerSpec (new ContainerSpec ().withImage (DEFAULT_IMAGE ).withMounts (Collections .singletonList (tmpMount )))))
123
+ .exec ();
124
+
125
+ List <Service > services = dockerRule .getClient ().listServicesCmd ()
126
+ .withNameFilter (Lists .newArrayList (SERVICE_NAME ))
127
+ .exec ();
128
+
129
+ assertThat (services , hasSize (1 ));
130
+ List <Mount > mounts = dockerRule .getClient ().inspectServiceCmd (SERVICE_NAME ).exec ().getSpec ().getTaskTemplate ()
131
+ .getContainerSpec ().getMounts ();
132
+ assertThat (mounts , hasSize (1 ));
133
+ assertThat (mounts .get (0 ), is (tmpMount ));
134
+ dockerRule .getClient ().removeServiceCmd (SERVICE_NAME ).exec ();
135
+ }
107
136
}
0 commit comments