Elffuss BraidHub

kikocis/java-driver public

ad13e242a65e · 5.8 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 MavenArtifactProvisionOption nettyBundle() {
61 return mavenBundle("io.netty", "netty", "3.9.0.Final");
62 }
63
64 private CompositeOption defaultOptions() {
65 return new CompositeOption() {
66
67 @Override public Option[] getOptions() {
68 return options(
69 systemProperty("cassandra.contactpoints").value(CCMBridge.IP_PREFIX + 1),
70 bundle("reference:file:target/classes"),
71 mavenBundle("com.codahale.metrics", "metrics-core", "3.0.2"),
72 mavenBundle("org.slf4j", "slf4j-api", "1.7.5"),
73 mavenBundle("org.slf4j", "slf4j-simple", "1.7.5").noStart(),
74 systemPackages("org.testng", "org.junit", "org.junit.runner", "org.junit.runner.manipulation",
75 "org.junit.runner.notification", "com.jcabi.manifests")
76 );
77 }
78 };
79 }
80
81 @Configuration
82 public Option[] shadedConfig() {
83 return options(
84 driverBundle(true),
85 guavaBundle(),
86 defaultOptions()
87 );
88 }
89
90 @Configuration
91 public Option[] defaultConfig() {
92 return options(
93 driverBundle(),
94 guavaBundle(),
95 nettyBundle(),
96 defaultOptions()
97 );
98 }
99
100 @Configuration
101 public Option[] guava15Config() {
102 return options(
103 driverBundle(),
104 nettyBundle(),
105 guavaBundle().version("15.0"),
106 defaultOptions()
107 );
108 }
109
110 @Configuration
111 public Option[] guava16Config() {
112 return options(
113 driverBundle(),
114 nettyBundle(),
115 guavaBundle().version("16.0.1"),
116 defaultOptions()
117 );
118 }
119
120 @Configuration
121 public Option[] guava17Config() {
122 return options(
123 driverBundle(),
124 nettyBundle(),
125 guavaBundle().version("17.0"),
126 defaultOptions()
127 );
128 }
129
130 @Configuration
131 public Option[] guava18Config() {
132 return options(
133 driverBundle(),
134 nettyBundle(),
135 guavaBundle().version("18.0"),
136 defaultOptions()
137 );
138 }
139
140 /**
141 * <p>
142 * Exercises a 'mailbox' service provided by an OSGi bundle that depends on the driver. Ensures that
143 * queries can be made through the service with the current given configuration.
144 * </p>
145 *
146 * The following configurations are tried (defined via methods with the @Configuration annotation):
147 * <ol>
148 * <li>Default bundle (Driver with all of it's dependencies)</li>
149 * <li>Shaded bundle (Driver with netty shaded)</li>
150 * <li>With Guava 15</li>
151 * <li>With Guava 16</li>
152 * <li>With Guava 17</li>
153 * <li>With Guava 18</li>
154 * </ol>
155 *
156 * @test_category packaging
157 * @expected_result Can create, retrieve and delete data using the mailbox service.
158 * @jira_ticket JAVA-620
159 * @since 2.0.10, 2.1.5
160 */
161 public void service_api_functional() throws MailboxException {
162 // Insert some data into mailbox for a particular user.
163 String recipient = "user@datastax.com";
164
165 try {
166 Collection<MailboxMessage> inMessages = new ArrayList<MailboxMessage>();
167 for (int i = 0; i < 30; i++) {
168 MailboxMessage message = new MailboxMessage(recipient, new GregorianCalendar(2015, 1, i).getTime(), recipient, "" + i);
169 inMessages.add(message);
170 service.sendMessage(message);
171 }
172
173 Collection<MailboxMessage> messages = service.getMessages(recipient);
174
175 assertEquals(messages, inMessages);
176 } finally {
177 service.clearMailbox(recipient);
178 }
179 }
180}