-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-10.0.x
- Loading branch information
Showing
8 changed files
with
545 additions
and
37 deletions.
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
...common/src/main/java/org/eclipse/jetty/session/infinispan/BoundDelegatingInputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.session.infinispan; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.ObjectInput; | ||
|
||
/** | ||
* BoundDelegatingInputStream | ||
* | ||
* An InputStream that delegates methods to an ObjectInput. The ObjectInput must start | ||
* with an integer containing the length of the data. | ||
*/ | ||
public class BoundDelegatingInputStream extends InputStream | ||
{ | ||
|
||
protected final ObjectInput objectInput; | ||
private final int length; | ||
private int position = 0; | ||
|
||
public BoundDelegatingInputStream(ObjectInput objectInput) throws IOException | ||
{ | ||
this.objectInput = objectInput; | ||
this.length = objectInput.readInt(); | ||
} | ||
|
||
@Override | ||
public int read() throws IOException | ||
{ | ||
if (position < length) | ||
{ | ||
position++; | ||
return objectInput.read(); | ||
} | ||
return -1; | ||
} | ||
|
||
@Override | ||
public int read(byte[] b) throws IOException | ||
{ | ||
int available = length - position; | ||
int read = -1; | ||
if (position == length) | ||
{ | ||
return read; | ||
} | ||
if (b.length > available) | ||
{ | ||
read = objectInput.read(b, 0, available); | ||
} | ||
else | ||
{ | ||
read = objectInput.read(b); | ||
} | ||
if (read != -1) | ||
{ | ||
position += read; | ||
} | ||
return read; | ||
} | ||
|
||
@Override | ||
public int read(byte[] b, int off, int len) throws IOException | ||
{ | ||
int read = -1; | ||
if (position == length) | ||
{ | ||
return read; | ||
} | ||
if (position + len > length) | ||
{ | ||
read = objectInput.read(b, off, length - position); | ||
} | ||
else | ||
{ | ||
read = objectInput.read(b, off, len); | ||
} | ||
if (read != -1) | ||
{ | ||
position += read; | ||
} | ||
return read; | ||
} | ||
|
||
@Override | ||
public long skip(long n) throws IOException | ||
{ | ||
long skip = 0; | ||
if (position + n < length) | ||
{ | ||
skip = objectInput.skip(length - position); | ||
} | ||
else | ||
{ | ||
skip = objectInput.skip(n); | ||
} | ||
if (skip > 0) | ||
{ | ||
position += skip; | ||
} | ||
return skip; | ||
} | ||
|
||
@Override | ||
public int available() throws IOException | ||
{ | ||
if (position < length) | ||
{ | ||
int available = objectInput.available(); | ||
if (position + available > length) | ||
{ | ||
return length - position; | ||
} | ||
else | ||
{ | ||
return available; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException | ||
{ | ||
objectInput.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
.../test/java/org/eclipse/jetty/server/session/ClusteredSerializedSessionScavengingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.server.session; | ||
|
||
import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStoreFactory; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* ClusteredSerializedSessionScavengingTest | ||
*/ | ||
public class ClusteredSerializedSessionScavengingTest extends AbstractClusteredSessionScavengingTest | ||
{ | ||
public static InfinispanTestSupport __testSupport; | ||
|
||
@BeforeAll | ||
public static void setup() throws Exception | ||
{ | ||
__testSupport = new InfinispanTestSupport(); | ||
__testSupport.setUseFileStore(true); | ||
__testSupport.setSerializeSessionData(true); | ||
__testSupport.setup(); | ||
} | ||
|
||
@AfterAll | ||
public static void teardown() throws Exception | ||
{ | ||
if (__testSupport != null) | ||
__testSupport.teardown(); | ||
} | ||
|
||
@Override | ||
@Test | ||
public void testClusteredScavenge() | ||
throws Exception | ||
{ | ||
super.testClusteredScavenge(); | ||
} | ||
|
||
/** | ||
* @see org.eclipse.jetty.server.session.AbstractTestBase#createSessionDataStoreFactory() | ||
*/ | ||
@Override | ||
public SessionDataStoreFactory createSessionDataStoreFactory() | ||
{ | ||
InfinispanSessionDataStoreFactory factory = new InfinispanSessionDataStoreFactory(); | ||
factory.setCache(__testSupport.getCache()); | ||
return factory; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ns/src/test/java/org/eclipse/jetty/server/session/InfinispanFileSessionDataStoreTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.server.session; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
/** | ||
* HotInitInfinispanSessionDataStoreTest | ||
*/ | ||
public class InfinispanFileSessionDataStoreTest extends InfinispanSessionDataStoreTest | ||
{ | ||
|
||
@BeforeEach | ||
public void setup() throws Exception | ||
{ | ||
_testSupport = new InfinispanTestSupport(); | ||
_testSupport.setUseFileStore(true); | ||
_testSupport.setup(); | ||
} | ||
|
||
} |
Oops, something went wrong.