Elffuss BraidHub

kikocis/java-driver public

33346b808ffb · 6.3 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 java.util.ArrayList;
19import java.util.Collection;
20import java.util.GregorianCalendar;
21
22import javax.inject.Inject;
23import org.ops4j.pax.exam.Configuration;
24import org.ops4j.pax.exam.Option;
25import org.ops4j.pax.exam.options.CompositeOption;
26import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
27import org.ops4j.pax.exam.options.UrlProvisionOption;
28import org.ops4j.pax.exam.testng.listener.PaxExam;
29import org.testng.annotations.Listeners;
30import org.testng.annotations.Test;
31
32import static org.ops4j.pax.exam.CoreOptions.*;
33import static org.testng.Assert.assertEquals;
34
35import com.datastax.driver.core.CCMBridge;
36import com.datastax.driver.osgi.api.MailboxException;
37import com.datastax.driver.osgi.api.MailboxMessage;
38import com.datastax.driver.osgi.api.MailboxService;
39
40import static com.datastax.driver.osgi.VersionProvider.projectVersion;
41
42@Listeners({CCMBridgeListener.class, PaxExam.class})
43@Test(groups="short")
44public class MailboxServiceIT {
45 @Inject MailboxService service;
46
47 private UrlProvisionOption driverBundle() {
48 return driverBundle(false);
49 }
50
51 private UrlProvisionOption driverBundle(boolean useShaded) {
52 String classifier = useShaded ? "-shaded" : "";
53 return bundle("reference:file:../../driver-core/target/cassandra-driver-core-" + projectVersion() + classifier + ".jar");
54 }
55
56 private MavenArtifactProvisionOption guavaBundle() {
57 return mavenBundle("com.google.guava", "guava", "14.0.1");
58 }
59
60 private CompositeOption nettyBundles() {
61 final String nettyVersion = "4.0.27.Final";
62 return new CompositeOption() {
63
64 @Override 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 public Option[] getOptions() {
80 return options(
81 systemProperty("cassandra.contactpoints").value(CCMBridge.IP_PREFIX + 1),
82 bundle("reference:file:target/classes"),
83 mavenBundle("com.codahale.metrics", "metrics-core", "3.0.2"),
84 mavenBundle("org.slf4j", "slf4j-api", "1.7.5"),
85 mavenBundle("org.slf4j", "slf4j-simple", "1.7.5").noStart(),
86 systemPackages("org.testng", "org.junit", "org.junit.runner", "org.junit.runner.manipulation",
87 "org.junit.runner.notification", "com.jcabi.manifests")
88 );
89 }
90 };
91 }
92
93 @Configuration
94 public Option[] shadedConfig() {
95 return options(
96 driverBundle(true),
97 guavaBundle(),
98 defaultOptions()
99 );
100 }
101
102 @Configuration
103 public Option[] defaultConfig() {
104 return options(
105 driverBundle(),
106 guavaBundle(),
107 nettyBundles(),
108 defaultOptions()
109 );
110 }
111
112 @Configuration
113 public Option[] guava15Config() {
114 return options(
115 driverBundle(),
116 nettyBundles(),
117 guavaBundle().version("15.0"),
118 defaultOptions()
119 );
120 }
121
122 @Configuration
123 public Option[] guava16Config() {
124 return options(
125 driverBundle(),
126 nettyBundles(),
127 guavaBundle().version("16.0.1"),
128 defaultOptions()
129 );
130 }
131
132 @Configuration
133 public Option[] guava17Config() {
134 return options(
135 driverBundle(),
136 nettyBundles(),
137 guavaBundle().version("17.0"),
138 defaultOptions()
139 );
140 }
141
142 @Configuration
143 public Option[] guava18Config() {
144 return options(
145 driverBundle(),
146 nettyBundles(),
147 guavaBundle().version("18.0"),
148 defaultOptions()
149 );
150 }
151
152 /**
153 * <p>
154 * Exercises a 'mailbox' service provided by an OSGi bundle that depends on the driver. Ensures that
155 * queries can be made through the service with the current given configuration.
156 * </p>
157 *
158 * The following configurations are tried (defined via methods with the @Configuration annotation):
159 * <ol>
160 * <li>Default bundle (Driver with all of it's dependencies)</li>
161 * <li>Shaded bundle (Driver with netty shaded)</li>
162 * <li>With Guava 15</li>
163 * <li>With Guava 16</li>
164 * <li>With Guava 17</li>
165 * <li>With Guava 18</li>
166 * </ol>
167 *
168 * @test_category packaging
169 * @expected_result Can create, retrieve and delete data using the mailbox service.
170 * @jira_ticket JAVA-620
171 * @since 2.0.10, 2.1.5
172 */
173 public void service_api_functional() throws MailboxException {
174 // Insert some data into mailbox for a particular user.
175 String recipient = "user@datastax.com";
176
177 try {
178 Collection<MailboxMessage> inMessages = new ArrayList<MailboxMessage>();
179 for (int i = 0; i < 30; i++) {
180 MailboxMessage message = new MailboxMessage(recipient, new GregorianCalendar(2015, 1, i).getTime(), recipient, "" + i);
181 inMessages.add(message);
182 service.sendMessage(message);
183 }
184
185 Collection<MailboxMessage> messages = service.getMessages(recipient);
186
187 assertEquals(messages, inMessages);
188 } finally {
189 service.clearMailbox(recipient);
190 }
191 }
192}