Elffuss BraidHub

kikocis/java-driver public

dc23ffd69e7e · 6.6 KiBRawPermalink
1/*
2 * Copyright (C) 2012-2015 DataStax Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.datastax.driver.osgi;
17
18import com.datastax.driver.core.TestUtils;
19import com.datastax.driver.osgi.api.MailboxException;
20import com.datastax.driver.osgi.api.MailboxMessage;
21import com.datastax.driver.osgi.api.MailboxService;
22import org.ops4j.pax.exam.Configuration;
23import org.ops4j.pax.exam.Option;
24import org.ops4j.pax.exam.options.CompositeOption;
25import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
26import org.ops4j.pax.exam.options.UrlProvisionOption;
27import org.ops4j.pax.exam.testng.listener.PaxExam;
28import org.testng.annotations.Listeners;
29import org.testng.annotations.Test;
30
31import javax.inject.Inject;
32import java.util.ArrayList;
33import java.util.Collection;
34import java.util.GregorianCalendar;
35
36import static com.datastax.driver.osgi.VersionProvider.projectVersion;
37import static org.ops4j.pax.exam.CoreOptions.*;
38import static org.testng.Assert.assertEquals;
39
40@Listeners({CCMBridgeListener.class, PaxExam.class})
41@Test(groups = "short")
42public class MailboxServiceIT {
43 @Inject
44 MailboxService service;
45
46 private UrlProvisionOption driverBundle() {
47 return driverBundle(false);
48 }
49
50 private UrlProvisionOption driverBundle(boolean useShaded) {
51 String classifier = useShaded ? "-shaded" : "";
52 return bundle("reference:file:../../driver-core/target/cassandra-driver-core-" + projectVersion() + classifier + ".jar");
53 }
54
55 private MavenArtifactProvisionOption guavaBundle() {
56 return mavenBundle("com.google.guava", "guava", "14.0.1");
57 }
58
59 private CompositeOption nettyBundles() {
60 final String nettyVersion = "4.0.27.Final";
61 return new CompositeOption() {
62
63 @Override
64 public Option[] getOptions() {
65 return options(
66 mavenBundle("io.netty", "netty-buffer", nettyVersion),
67 mavenBundle("io.netty", "netty-codec", nettyVersion),
68 mavenBundle("io.netty", "netty-common", nettyVersion),
69 mavenBundle("io.netty", "netty-handler", nettyVersion),
70 mavenBundle("io.netty", "netty-transport", nettyVersion)
71 );
72 }
73 };
74 }
75
76 private CompositeOption defaultOptions() {
77 return new CompositeOption() {
78
79 @Override
80 public Option[] getOptions() {
81 return options(
82 systemProperty("cassandra.contactpoints").value(TestUtils.IP_PREFIX + 1),
83 bundle("reference:file:target/classes"),
84 bootDelegationPackages("javax.security.*"),
85 mavenBundle("com.codahale.metrics", "metrics-core", "3.0.2"),
86 mavenBundle("org.slf4j", "slf4j-api", "1.7.5"),
87 mavenBundle("org.slf4j", "slf4j-simple", "1.7.5").noStart(),
88 systemPackages("org.testng", "org.junit", "org.junit.runner", "org.junit.runner.manipulation",
89 "org.junit.runner.notification", "com.jcabi.manifests")
90 );
91 }
92 };
93 }
94
95 @Configuration
96 public Option[] shadedConfig() {
97 return options(
98 driverBundle(true),
99 guavaBundle(),
100 defaultOptions()
101 );
102 }
103
104 @Configuration
105 public Option[] defaultConfig() {
106 return options(
107 driverBundle(),
108 guavaBundle(),
109 nettyBundles(),
110 defaultOptions()
111 );
112 }
113
114 @Configuration
115 public Option[] guava15Config() {
116 return options(
117 driverBundle(),
118 nettyBundles(),
119 guavaBundle().version("15.0"),
120 defaultOptions()
121 );
122 }
123
124 @Configuration
125 public Option[] guava16Config() {
126 return options(
127 driverBundle(),
128 nettyBundles(),
129 guavaBundle().version("16.0.1"),
130 defaultOptions()
131 );
132 }
133
134 @Configuration
135 public Option[] guava17Config() {
136 return options(
137 driverBundle(),
138 nettyBundles(),
139 guavaBundle().version("17.0"),
140 defaultOptions()
141 );
142 }
143
144 @Configuration
145 public Option[] guava18Config() {
146 return options(
147 driverBundle(),
148 nettyBundles(),
149 guavaBundle().version("18.0"),
150 defaultOptions()
151 );
152 }
153
154 /**
155 * <p>
156 * Exercises a 'mailbox' service provided by an OSGi bundle that depends on the driver. Ensures that
157 * queries can be made through the service with the current given configuration.
158 * </p>
159 * <p/>
160 * The following configurations are tried (defined via methods with the @Configuration annotation):
161 * <ol>
162 * <li>Default bundle (Driver with all of it's dependencies)</li>
163 * <li>Shaded bundle (Driver with netty shaded)</li>
164 * <li>With Guava 15</li>
165 * <li>With Guava 16</li>
166 * <li>With Guava 17</li>
167 * <li>With Guava 18</li>
168 * </ol>
169 *
170 * @test_category packaging
171 * @expected_result Can create, retrieve and delete data using the mailbox service.
172 * @jira_ticket JAVA-620
173 * @since 2.0.10, 2.1.5
174 */
175 public void service_api_functional() throws MailboxException {
176 // Insert some data into mailbox for a particular user.
177 String recipient = "user@datastax.com";
178
179 try {
180 Collection<MailboxMessage> inMessages = new ArrayList<MailboxMessage>();
181 for (int i = 0; i < 30; i++) {
182 MailboxMessage message = new MailboxMessage(recipient, new GregorianCalendar(2015, 1, i).getTime(), recipient, "" + i);
183 inMessages.add(message);
184 service.sendMessage(message);
185 }
186
187 Collection<MailboxMessage> messages = service.getMessages(recipient);
188
189 assertEquals(messages, inMessages);
190 } finally {
191 service.clearMailbox(recipient);
192 }
193 }
194}