Elffuss BraidHub

kikocis/java-driver public

01295193b436 · 4.0 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.osgi.api.MailboxException;
19import com.datastax.driver.osgi.api.MailboxMessage;
20import com.datastax.driver.osgi.api.MailboxService;
21import org.ops4j.pax.exam.Configuration;
22import org.ops4j.pax.exam.Option;
23import org.ops4j.pax.exam.testng.listener.PaxExam;
24import org.testng.annotations.Listeners;
25import org.testng.annotations.Test;
26
27import javax.inject.Inject;
28import java.util.ArrayList;
29import java.util.Collection;
30import java.util.GregorianCalendar;
31
32import static com.datastax.driver.osgi.BundleOptions.*;
33import static org.ops4j.pax.exam.CoreOptions.options;
34import static org.testng.Assert.assertEquals;
35
36@Listeners({CCMBridgeListener.class, PaxExam.class})
37@Test(groups = "short")
38public class MailboxServiceIT {
39 @Inject
40 MailboxService service;
41
42 @Configuration
43 public Option[] shadedConfig() {
44 return options(
45 driverBundle(true),
46 mailboxBundle(),
47 guavaBundle(),
48 defaultOptions()
49 );
50 }
51
52 @Configuration
53 public Option[] defaultConfig() {
54 return options(
55 driverBundle(),
56 mailboxBundle(),
57 guavaBundle(),
58 nettyBundles(),
59 defaultOptions()
60 );
61 }
62
63 @Configuration
64 public Option[] guava17Config() {
65 return options(
66 driverBundle(),
67 mailboxBundle(),
68 nettyBundles(),
69 guavaBundle().version("17.0"),
70 defaultOptions()
71 );
72 }
73
74 @Configuration
75 public Option[] guava18Config() {
76 return options(
77 driverBundle(),
78 mailboxBundle(),
79 nettyBundles(),
80 guavaBundle().version("18.0"),
81 defaultOptions()
82 );
83 }
84
85 /**
86 * <p>
87 * Exercises a 'mailbox' service provided by an OSGi bundle that depends on the driver. Ensures that
88 * queries can be made through the service with the current given configuration.
89 * </p>
90 * <p/>
91 * The following configurations are tried (defined via methods with the @Configuration annotation):
92 * <ol>
93 * <li>Default bundle (Driver with all of it's dependencies)</li>
94 * <li>Shaded bundle (Driver with netty shaded)</li>
95 * <li>With Guava 16.0.1</li>
96 * <li>With Guava 17</li>
97 * <li>With Guava 18</li>
98 * </ol>
99 *
100 * @test_category packaging
101 * @expected_result Can create, retrieve and delete data using the mailbox service.
102 * @jira_ticket JAVA-620
103 * @since 2.0.10, 2.1.5
104 */
105 public void service_api_functional() throws MailboxException {
106 // Insert some data into mailbox for a particular user.
107 String recipient = "user@datastax.com";
108
109 try {
110 Collection<MailboxMessage> inMessages = new ArrayList<MailboxMessage>();
111 for (int i = 0; i < 30; i++) {
112 MailboxMessage message = new MailboxMessage(recipient, new GregorianCalendar(2015, 1, i).getTime(), recipient, "" + i);
113 inMessages.add(message);
114 service.sendMessage(message);
115 }
116
117 Collection<MailboxMessage> messages = service.getMessages(recipient);
118
119 assertEquals(messages, inMessages);
120 } finally {
121 service.clearMailbox(recipient);
122 }
123 }
124}