|
ActiveMQ example source code file (JournalImplTest.java)
The ActiveMQ JournalImplTest.java source code/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.activemq.kaha.impl.async; import java.io.File; import java.io.IOException; import java.util.ArrayList; import junit.framework.TestCase; import org.apache.activeio.journal.InvalidRecordLocationException; import org.apache.activeio.journal.RecordLocation; import org.apache.activeio.packet.ByteArrayPacket; import org.apache.activeio.packet.Packet; import org.apache.activemq.kaha.impl.async.JournalFacade.RecordLocationFacade; import org.apache.activemq.kaha.impl.async.ReadOnlyAsyncDataManager; import org.apache.activemq.util.ByteSequence; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Tests the AsyncDataManager based Journal * * */ public class JournalImplTest extends TestCase { Logger log = LoggerFactory.getLogger(JournalImplTest.class); int size = 1024 * 10; int logFileCount = 2; File logDirectory = new File("target/dm-data2"); private JournalFacade journal; /** * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { if (logDirectory.exists()) { deleteDir(logDirectory); } assertTrue("Could not delete directory: " + logDirectory.getCanonicalPath(), !logDirectory.exists()); AsyncDataManager dm = new AsyncDataManager(); dm.setDirectory(logDirectory); dm.setMaxFileLength(1024 * 64); dm.start(); journal = new JournalFacade(dm); } /** */ private void deleteDir(File f) { File[] files = f.listFiles(); for (int i = 0; i < files.length; i++) { File file = files[i]; file.delete(); } f.delete(); } protected void tearDown() throws Exception { journal.close(); if (logDirectory.exists()) { deleteDir(logDirectory); } // assertTrue( !logDirectory.exists() ); } public void testLogFileCreation() throws IOException { RecordLocation mark = journal.getMark(); assertNull(mark); } @SuppressWarnings("unchecked") public void testAppendAndRead() throws InvalidRecordLocationException, InterruptedException, IOException { Packet data1 = createPacket("Hello World 1"); RecordLocation location1 = journal.write(data1, false); Packet data2 = createPacket("Hello World 2"); RecordLocation location2 = journal.write(data2, false); Packet data3 = createPacket("Hello World 3"); RecordLocation location3 = journal.write(data3, false); // Thread.sleep(1000); // Now see if we can read that data. Packet data; data = journal.read(location2); assertEquals(data2, data); data = journal.read(location1); assertEquals(data1, data); data = journal.read(location3); assertEquals(data3, data); // Can we cursor the data? RecordLocation l = journal.getNextRecordLocation(null); int t = l.compareTo(location1); assertEquals(0, t); data = journal.read(l); assertEquals(data1, data); l = journal.getNextRecordLocation(l); assertEquals(0, l.compareTo(location2)); data = journal.read(l); assertEquals(data2, data); l = journal.getNextRecordLocation(l); assertEquals(0, l.compareTo(location3)); data = journal.read(l); assertEquals(data3, data); l = journal.getNextRecordLocation(l); assertNull(l); log.info(journal.toString()); } public void testReadOnlyRead() throws InvalidRecordLocationException, InterruptedException, IOException { Packet data1 = createPacket("Hello World 1"); RecordLocation location1 = journal.write(data1, false); Packet data2 = createPacket("Hello World 2"); RecordLocation location2 = journal.write(data2, false); Packet data3 = createPacket("Hello World 3"); RecordLocation location3 = journal.write(data3, false); Packet packet; packet = journal.read(location2); assertEquals(data2, packet); packet = journal.read(location1); assertEquals(data1, packet); packet = journal.read(location3); assertEquals(data3, packet); ArrayList<File> data = new ArrayList Other ActiveMQ examples (source code examples)Here is a short list of links related to this ActiveMQ JournalImplTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.