()
| 89 | } |
| 90 | |
| 91 | protected static void testQuotes() throws Exception { |
| 92 | System.out.println("And now for something completely different..."); |
| 93 | |
| 94 | final AtomicInteger count = new AtomicInteger(); |
| 95 | |
| 96 | final Lock lock = new ReentrantLock(); |
| 97 | final Condition finished = lock.newCondition(); |
| 98 | |
| 99 | publisher.create_datawriter(topic, DATAWRITER_QOS_DEFAULT.get(), |
| 100 | new DDS._DataWriterListenerLocalBase() { |
| 101 | public void on_liveliness_lost(DataWriter dw, LivelinessLostStatus status) {} |
| 102 | |
| 103 | public void on_offered_deadline_missed(DataWriter dw, OfferedDeadlineMissedStatus status) {} |
| 104 | |
| 105 | public void on_offered_incompatible_qos(DataWriter dw, OfferedIncompatibleQosStatus status) {} |
| 106 | |
| 107 | public void on_publication_matched(DataWriter dw, PublicationMatchedStatus status) { |
| 108 | try { |
| 109 | if (status.current_count == 0) return; |
| 110 | // Don't run the rest of this method if the callback is |
| 111 | // due to the datareader going away. |
| 112 | |
| 113 | DataDataWriter writer = DataDataWriterHelper.narrow(dw); |
| 114 | |
| 115 | //NOTE: Since we are testing a complex type which contains a |
| 116 | // union, both variants (DATA_IDL, DATA_STREAM) must be |
| 117 | // tested on the same set of data: |
| 118 | |
| 119 | List<Data> dataItems = new ArrayList<Data>(); |
| 120 | |
| 121 | for (Quote quote : quotes) { |
| 122 | // DATA_IDL |
| 123 | dataItems.add(createData(quote)); |
| 124 | |
| 125 | // DATA_STREAM |
| 126 | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 127 | |
| 128 | ObjectOutputStream os = new ObjectOutputStream(out); |
| 129 | os.writeObject(quote.line); // Quote is not Serializable |
| 130 | |
| 131 | dataItems.add(createData(out.toByteArray())); |
| 132 | } |
| 133 | |
| 134 | count.set(dataItems.size()); |
| 135 | |
| 136 | for (Data data : dataItems) { |
| 137 | int result = writer.write(data, HANDLE_NIL.value); |
| 138 | assert (result != RETCODE_ERROR.value); |
| 139 | } |
| 140 | |
| 141 | } catch (Throwable t) { |
| 142 | t.printStackTrace(); |
| 143 | } |
| 144 | }; |
| 145 | }, DEFAULT_STATUS_MASK.value |
| 146 | ); |
| 147 | |
| 148 | lock.lock(); |
no test coverage detected